Skip to content

fix(coderd/x/chatd): close three view_image follow-ups from the #250 review - #382

Merged
ibetitsmike merged 3 commits into
mainfrom
mike/issue-291-view-image
Nov 17, 2026
Merged

ibetitsmike merged 3 commits into
mainfrom
mike/issue-291-view-image

Conversation

@ibetitsmike

Copy link
Copy Markdown
Owner

Coder Agents opened this PR on behalf of @ibetitsmike.

Closes #291.

Three follow-ups from the #250 review of fork-view-image. All fork logic lives in fork_*.go files behind the existing fork-view-image experiment. No new dependency. No changes outside coderd/x/chatd.

Fixed

1. Animated WebP is rejected

viewImage now walks the RIFF container of a image/webp file and rejects it when it finds an ANMF frame chunk or a VP8X chunk with the animation flag bit set. Error text tells the model to save one frame as a PNG. See webpAnimated in coderd/x/chatd/fork_view_image.go. The tests build minimal WebP byte streams in the test file, so no fixture or decoder is needed.

2. The image count bound now counts every other image

limitViewedImages used to exempt the newest viewed image from all bounds. It keeps that byte-budget exemption, but it no longer escapes the count: kept < maxViewedImagesInPrompt and otherImages+kept < maxImagesInPrompt now apply to the newest image too. Twenty other images plus two viewed images now drop both viewed images, where before the newest one stayed in the prompt.

3. Bound ownership follows the custom agent tool policy

The view_image limit logic decided ownership from the chat's dynamic tools before the custom agent tool policy filtered them, so a dynamic view_image that the policy dropped still kept its images unbounded. turn_environment.go now resolves the policy before appendForkTools and passes it in through a new forkToolsWithCustomAgentPolicy option. dynamicToolOwnsViewImage takes the policy and returns false when the policy allowlist leaves the tool out. The compaction path receives the same policy through generationCompaction, so a compaction override model cannot re-expand the prompt.

Declined from #291, with reasons

Item Reason
WebP bitstream decoding (full animation decode) Needs a WebP decoder dependency. The animated rejection above covers the failure mode: a stored image OpenAI later rejects.
Later frames of animated GIFs Animated GIFs are already rejected outright, so there are no later frames in the prompt.
Compaction head budget The current behavior only drops a viewed image slightly early during compaction. The fix is not a few obvious lines, so it stays out of scope here.
Per-frame limits inside an ANMF stream Covered by rejecting animated WebP entirely; no frame ever reaches the prompt.

Tests

New tests in coderd/x/chatd/fork_view_image_internal_test.go:

  • TestViewImageTool/AnimatedWebP: VP8X-flag and ANMF files are rejected with the animated error, a still VP8X file is accepted.
  • TestLimitViewedImages/OtherImagesFillTheCount: 20 other images plus 2 viewed drops both viewed images; 19 other images keeps the newest.
  • TestViewImageToolGate/OffWithDynamicToolDroppedByPolicy and /OffWithDynamicToolKeptByPolicy: with fork-view-image off and a dynamic view_image, a policy allowlist without the tool bounds the images, one with the tool leaves them unbounded.

Commands run, each under flock ~/.fork-go.lock:

  • go test ./coderd/x/chatd/ -count=1: PASS, full package.
  • golangci-lint run --config=.golangci.new-code.yaml --new-from-merge-base=origin/main ./coderd/x/chatd/: 0 issues.
  • make gen: no working-tree changes from this PR.

Negative controls

Each fix was reverted once on this exact tree and its test failed, then restored:

  • Animated check disabled: TestViewImageTool/AnimatedWebP FAIL (accepted /anim-x.webp).
  • Old keep condition restored: TestLimitViewedImages/OtherImagesFillTheCount FAIL (newest image kept).
  • Policy check removed: TestViewImageToolGate/OffWithDynamicToolDroppedByPolicy FAIL (prompt not bounded).

Not verified

  • No runtime or dogfood run: the three fixes are unit-tested but were not exercised against a live model.
  • make lint (full target) has 112 pre-existing issues on main, including this branch's base, and its auto-fix mode rewrites unrelated files; only the scoped new-code lint was run.

…review

An animated WebP now fails like an animated GIF: a VP8X header with the
animation flag or any ANMF chunk makes the tool reject the file, so a
stored result cannot fail every later request on OpenAI.

The prompt bound no longer exempts the newest viewed image from the image
count. A prompt that already holds maxImagesInPrompt other images drops
every viewed image instead of going over Anthropic's 20 image threshold.
The newest one still ignores the byte budget alone, so a single large
view stays visible.

The viewed-image bound follows the turn's custom agent tool policy. A
dynamic view_image that the policy drops no longer owns the name, so the
bound applies; one the policy keeps still owns it. The policy resolves
before the appendForkTools hook in buildTurnEnvironment, and the
compaction path gets the same policy through generationCompaction.

Closes #291.
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Coder Agents acted on behalf of @ibetitsmike.

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-17T16:57:15.078963Z ed41291 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 96eceb22cf

ℹ️ 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".

Comment thread coderd/x/chatd/fork_view_image.go Resolved
Comment thread coderd/x/chatd/fork_view_image.go Resolved
…olicy filter

Codex review of 96eceb2 found that the new policy check in
dynamicToolOwnsViewImage diverged from customAgentToolPolicy.filter:
a policy with Tools nil kept a dynamic view_image in the tool list,
but the check dropped it and bounded its images; a policy that kept
it in Tools but dropped it through read_only or disallowed_tools kept
ownership while the tool was gone. A shared keepsDynamicViewImage
decision now serves both paths. The gate test covers read-only and
disallowed_tools policies. An architecture TODO records the changed
count bound and the policy ownership for the human owner.
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Coder Agents acted on behalf of @ibetitsmike.

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 19f932657b

ℹ️ 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".

Comment thread coderd/x/chatd/ARCHITECTURE.md Resolved
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Coder Agents acted on behalf of @ibetitsmike.

@codex review

The two threads of the previous review are fixed (19f9326) or answered (the architecture TODO is required by AGENTS.md L75-76 and by the earlier finding 4601899025, and stays for the human PR author). Both are resolved.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: 19f932657b

ℹ️ 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".

… into the architecture bullet

Per the lead decision since 2026-11-16, fork PRs write final prose in the
fork-owned architecture sections instead of leaving TODO comments. The
TODO is gone: the fork-view-image bullet now states that the newest
viewed image alone ignores the 10 MiB byte budget but still drops while
other images fill the 20-image count, and that while fork-view-image is
off the dynamic view_image owns the bound only when the chat's custom
agent tool policy keeps it, through dynamicToolOwnsViewImage and
customAgentToolPolicy.keepsDynamicViewImage.
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Coder Agents acted on behalf of @ibetitsmike.

@codex review

ed41291 removes the architecture TODO and writes its content as final prose into the fork-view-image bullet, per the lead maintainer's standing decision that fork PRs update the fork-owned ARCHITECTURE.md sections directly (precedent PRs #272, #278, #281, #363, #366).

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: ed41291791

ℹ️ 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".

@ibetitsmike
ibetitsmike merged commit b25a79b into main Nov 17, 2026
9 checks passed
@ibetitsmike
ibetitsmike deleted the mike/issue-291-view-image branch November 17, 2026 17:21
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Coder Agents acted on behalf of @ibetitsmike.

Merged at head ed412917917e65be1578d9d383b8379b47b5a175 as b25a79b, on main 99056e8fef081ba67c78cd0cb2126ce998ef7bf5, with the server running that main.

Gates on this exact head:

  1. The head matched the SHA I verified (--match-head-commit).
  2. Every check run passed. fork-ci run 44130946277 passed on this head.
  3. Codex receipt for this head: fix(coderd/x/chatd): close three view_image follow-ups from the #250 review #382 (comment) ("Didn't find any major issues").
  4. No unresolved review thread.
  5. 0 commits behind main.
  6. I ran the tests below on this exact head.

Tests I ran on ed41291791 (detached worktree, under flock ~/.fork-go.lock):

  • go test -count=1 -race -v -run 'ViewImage|ViewedImage|CustomAgentToolPolicy' ./coderd/x/chatd/: 51 PASS, 0 FAIL.
  • go test -count=1 ./coderd/x/chatd/...: 21 packages ok.
  • go vet ./coderd/x/chatd/: clean.
  • Negative control 1: with the old keep condition (kept == 0 || ...) restored in limitViewedImages, TestLimitViewedImages/OtherImagesFillTheCount fails.
  • Negative control 2: with the animated WebP rejection disabled, TestViewImageTool/AnimatedWebP fails.
  • The source was restored after each control.

Review notes:

  • Fixed: an animated WebP (VP8X animation flag or any ANMF chunk) is rejected like an animated GIF. webpAnimated runs after webpComplete has checked that every chunk fits in the file.
  • Fixed: the 20-image count now applies to the newest viewed image too. That image alone still ignores the 10 MiB byte budget.
  • Fixed: while fork-view-image is off, a dynamic view_image owns the bound only when the custom agent tool policy keeps it. keepsDynamicViewImage follows the same read_only, disallowed_tools and allowlist rules as the policy filter. turn_environment.go now resolves the policy before the fork hook, and compaction gets the same policy.
  • Declined, with reasons in the PR body: WebP bitstream decoding (needs a decoder dependency), later GIF frames (animated GIFs are rejected), compaction head budget.
  • The ARCHITECTURE.md fork-view-image bullet is updated in final prose, following the lead decision for fork sections.
  • Stays behind fork-view-image.

Not exercised:

  • a live model request with a viewed animated WebP, or with more than 20 images in one prompt;
  • a real custom agent with a dynamic view_image tool.

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.

chatd: view_image follow-ups declined from the #250 review

1 participant