Repository navigation
feat(serve): image upload, prompt images and image read route (#558) - #562
Merged
Merged
Conversation
🔍 Cora AI Code Review✅ No issues found. Code looks good! Review powered by cora-code · BYOK · MIT |
POST /sessions/{id}/images stores a raw body (type sniffed from the bytes) through the core image resolve path, content-addressed under the spill dir; prompts reference uploads with an images array and record durable references only; GET /sessions/{id}/images/{fnv1a64} serves an image only when the session log records it, re-checking jail, size and hash. Per-session and total upload quotas are env-configurable.
The upload ceiling depends on the token, so answering 413 before auth let a client tell a right token from a wrong one with no recorded failure, outside the per-IP limiter. An oversized body now goes through the limiter first: a wrong or missing token gets 401 and counts as a failure, only the right token gets 413.
ajianaz
force-pushed
the
feat/558-serve-images
branch
from
November 11, 2026 01:50
103a2ef to
8056622
Compare
3 tasks
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.
What
Image input for graphical clients on
tole serve, behind the existing bearer token:POST /sessions/{id}/images: upload one image as the raw request body. Answers{id, mime, bytes, fnv1a64}. The id is the content hash, and no server path is returned.POST /sessions/{id}/promptaccepts"images": [<id>]next totext.GET /sessions/{id}/images/{fnv1a64}: returns the bytes of an image recorded in that session's log.Closes #558
Why
Image input exists in
tole-core(#212) and the CLI (--image), but the serve face had no way to attach or show an image. Mobile, desktop and web clients (epic #523) need it.Changes
tole_cli::serve_imagesmodule (UploadStore,read_recorded,ImageApiError,Quotas).Content-Typeis ignored. The body goes through the same core path as--image:tole_core::image::resolve(jail, 10 MiB cap, sniff, FNV-1a 64). It is stored content-addressed at<spill dir>/serve/<session id>/<fnv1a64>.<ext>. The provider already reads images from the spill dir, so images are re-sent after a restart andresume. Uploading the same bytes again returns the same reference and uses no extra quota.--image; the image data is never written to the log.Content-Type(the recorded mime),X-Content-Type-Options: nosniffandCache-Control: private, no-store.TOLE_SERVE_IMAGE_SESSION_QUOTA(default 64 MiB per session) andTOLE_SERVE_IMAGE_TOTAL_QUOTA(default 512 MiB across all serve sessions). A quota check and its write happen under one lock, so two concurrent uploads cannot both pass a check that only one fits.0disables uploads.400empty body, bad id, orimagesthat is not an array of ids ·401·403recorded image outside the jail ·404unknown session, upload or unrecorded image ·409hash, size or type mismatch (reported, never served or sent) ·413·415not an image ·503no data dir ·507quota exceeded.serve.rs:401and counts against the per-IP auth limiter (429after 10 failures a minute); only the right token gets413. Without this the size answer was a token-validity oracle outside the limiter.session_host::run_session_turn_with_imagesandturn_runner::run_turn_on_with_imagesfrom feat(core,cli): images on any turn, ACP image blocks, and a decision on an image-reading tool #559 (rebased onto develop after feat(cli): images on any turn and ACP image blocks (#559) #563; no duplicate helpers).image_rootsandspill_dirare nowpub(crate).tole-corechange.docs/mobile-control.md(new Images section), README (status line and image input section),docs/epics.md, CHANGELOGUnreleased.data:URLs in the prompt JSON (by decision).--imagespills.Testing
cargo fmt --all -- --checkandcargo clippy --workspace --all-targets -- -D warningsclean;cargo check -p tole-cli --no-default-featuresclean;cargo test --workspace: 1233 passed, 0 failed.crates/tole-cli/tests/serve_images.rs(5 tests):data:image/pngpart and the log holds the reference only. Reading the image back returns the exact bytes withContent-Typeandnosniff.404before resume, served afterresume, and re-sent on the next turn.409on read and on prompt. Images that are unrecorded, belong to another session, or have a junk hash return404.image/pngheader (415), empty body (400), more than 10 MiB with the token (413), unknown session (404), unauthenticated upload and read (401), an unauthenticated 2 MiB declared upload (401). Badimagesvalues return400/404. Refused uploads leave no file behind.401ten times, then429, after which even the right token is refused for that IP.507, and the message names the env variable.serve_imagescover quota parsing, dedupe and session scoping, non-image/empty/quota refusals, and read checks: jail403, swapped409, missing404./), "served only when recorded", the id validation on prompt lookup, the content sniff.cora review --stagedwas not run because cora is not installed in this environment. A manual review of the staged diff covered correctness, jail and path traversal, size-limit and quota bypass, and error paths; the CI Cora Review is the gate.Cross-Compile (aarch64-apple-ios)is cancelled before it starts (no log), as on already-merged PRs such as fix(storage): retry a writer lock that names our own pid (#552) #557; it is a runner issue, not this change.