Repository navigation
feat(agent): read chat attachments on demand - #4203
Merged
Merged
Conversation
lyingbug
force-pushed
the
cursor/67517c0e
branch
from
October 12, 2026 13:05
1e1f55f to
7ade8f9
Compare
lyingbug
marked this pull request as ready for review
October 13, 2026 06:20
Agent turns pasted query-selected attachment excerpts into the prompt before the model could act. List stored files as a manifest so the agent can page and search them through read_attachment.
Merge read_attachment into read_file (attachment:// paths, numbered document images, staged-copy aliasing, query search), return sandbox images as images, describe images for non-vision models inside the tool call with bounded concurrency and model-chosen detail/focus, render image reads in the UI, and record image metadata in Langfuse.
…on cache - ReadImages authorizes once and describes images in parallel - start VLM deadlines after a slot is held; longer timeout for full reads - detach shared description calls from the first caller's context - skip rewriting unchanged sandbox projections - strip the description cache from temporary document API responses - render upload text before calling the vision model
…t UI - return resolved images in document order instead of reverse - show attachment file names instead of attachment:// IDs in tool titles - use the shared file icon and a lighter card for chat attachments
Main already took sqlite 000035 and versioned 000116, so the attachment lookup indexes move to the next free numbers. Also wrap the ReadImages signature and drop an unused test parameter.
lyingbug
force-pushed
the
cursor/67517c0e
branch
from
October 13, 2026 06:30
f5aac4a to
cefc035
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Agent conversations expose uploaded attachments through compact manifests and
read_fileatattachment://paths. Small ready files remain inline; larger files can be paged or searched on demand, including during history replay. Reading and image-observation reuse work independently of a sandbox.next_offset/next_line_offsetcursors cover oversized lines, expired excerpts, and staged copies. Reserve metadata space before pagination so registry truncation cannot skip content.briefplusfocus. Guidance reservesfullfor an explicit close-reading request and caps full reads at one image; explicit brief batches are capped at four. Shorten the shared VLM prompts and preserve partial failures and continuation.Architecture
application/attachmentowns session-authorized reads, parse waits, image preparation, observation reuse, and optional projection coordination.read_fileconsumesinterfaces.AttachmentReaderand handles URI routing, pagination, and presentation. Repository and sandbox adapters provide persistence and copies; the Agent engine handles model transport and generic image fallback.Split upload/lifecycle handling, parsing/OCR/chunking, and prompt assembly into separate service files. Document responsibilities and runtime flow in
internal/application/attachment/README.md.Validation
Passed:
go test ./internal/application/attachment ./internal/application/repository ./internal/agent/... ./internal/application/service ./internal/types ./internal/handler/session ./internal/models/chat ./internal/modelcontext ./internal/im ./internal/database-race.go build ./...,go vet ./..., and diff whitespace checks.golangci-lint run --new-from-rev=ef54e835c907718cedf7316bfa93daf69a28b2ba ./...— 0 issues.Regression coverage includes 9 MiB paging/search, lossless multilingual long-line continuation, output-budget reconstruction, bounded image reads, authorization before storage access, cross-reader cache reuse, detail/focus/model/image invalidation, failed-description retry, concurrent cache updates, tenant isolation, document deletion, same-turn parsed-file synchronization, and sandbox reconstruction without another VLM call. The original three pagination regressions failed against the previous PR head before their fixes.
Tests run with the local
LOG_FORMAToverride removed because it affects existing logging assertions. PostgreSQL/MySQL integration, frontend checks, the full repository test suite, and live-model conversations were not rerun for this update. Earlier PR validation covered retention and index migrations on PostgreSQL 17.Compatibility notes
Existing originals and images in legacy temporary buckets are not migrated; provider lifecycle deletion can still make them unavailable. Uploads and reads continue to use the default file service. This change does not add tenant-specific storage routing.
Observation reuse requires the same model ID and normalized reading prompt; it does not infer semantic equivalence between different focus strings. Native-vision reasoning is not persisted as a separate attachment observation.