Repository navigation
feat(coderd/x/chatd): bound the viewed images a prompt carries - #309
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.
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: ce6b152759
ℹ️ 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. You're on a roll. 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/fork_tools.go # coderd/x/chatd/fork_view_image.go # coderd/x/chatd/fork_view_image_internal_test.go # coderd/x/chatd/turn_environment.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. Nice work! 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 667f057 (squash) at 07:04Z. Before the merge, the server was confirmed on the previous deploy, e44cdc1. Gates on head 90bf3f9:
Not exercised: a real provider run, and an end-to-end run with viewed images over a compaction override's limit. |
Part of #250. Middle of a three-PR stack that replaces #284. #308 is merged, and this PR is now based on
main. The top PR, #310, adds the structure and decode checks, the per-response call limit and the docs.Declined review findings worth doing later are collected in #291.
What
The prompt bound for viewed images, so base64 does not grow without bound over a long chat.
appendForkToolspasses the prompt throughlimitViewedImageson every step. The prompt keeps the newest 8view_imageimages, and always the newest one.computerscreenshots and attachments, so viewed images only fill what is left. That includes the attachments of the unanswered user tail, whichbuildTurnEnvironmentappends after the bound, soturn_environment.go:743passespendingPrompttoo.[image no longer in context: only the newest viewed images are kept. Call view_image again to see it.]followed by the original text. The stored conversation keeps every image.view_imagelimit becomes the note[image omitted: N bytes is larger than the view_image limit of M bytes for this model. ...].fork-view-imageis off and the turn offers the chat's dynamic tools with one namedview_image, the caller's tool owns the name, so the bound does not touch its results. Plan-mode turns, explore children and deployments that disable caller-supplied tools offer no dynamic tools, so the bound runs there.generation.go:1339.Size
362 added and 13 removed lines, of which 191 are tests. No generated files.
Tests
TestLimitViewedImages: the count bound, the byte bound, the newest kept, the input left unchanged, other media taking the byte budget first (a screenshot and an attachment), the pending tail's attachments taking it too, other images taking the image count (a PDF does not), a reused call ID, and the per-model size limit.TestViewImageToolGate: the prompt bound with the experiment on and off, no bound when a dynamicview_imageowns the name with the experiment off, except in plan mode, and the same forlimitViewedImagesForModel.limitViewedImagescall removed, bothTestViewImageToolGatebound subtests fail. With the other-media count, the dynamic-tool check, the plan-mode check, the pending tail or the image count removed,TestLimitViewedImages/OtherMediaTakesBudget,TestViewImageToolGate/OffWithDynamicTool,/OffWithDynamicToolInPlanMode,TestLimitViewedImages/PendingMediaTakesBudgetand/OtherImagesTakeCountfail.Commands run on this head, all under
flock ~/.fork-go.lock:go test ./coderd/x/chatd/ -run 'TestViewImage|TestLimitViewedImages|ForkTools|TestForkWorktreeBinding|AgentToolPolicy|CustomAgent|MediaSanitize|ReplaceUnsupportedMedia|DynamicTool|CompactionModelOverride' -count=1 -v: passgolangci-lint run --fix=false --config=.golangci.new-code.yaml --new-from-merge-base=origin/main ./coderd/x/chatd/: 0 issues. The default config reports no finding in the changed files.After the merge of
main(e44cdc1) the same tests pass on the new head, and fork-ci runs on it.Not verified
TestViewImageToolGatecoverslimitViewedImagesForModelitself.