Photos: architecture and design (grill first, then mockup) #505

Open
opened 2026-10-16 17:08:19 +00:00 by kayg · 8 comments
Owner

kayg (2026-10-16): start the Photos feature, grill-first. Architecture and design only; mockups allowed, no implementation yet.

Already decided elsewhere:

  • files live in Photos/YYYY/YYYY-MM-DD/ (G12);
  • XMP sidecars hold metadata, Archive and Hide (#412);
  • devices keep thumbnails always and originals on demand or pinned (ADR 0046);
  • expensive work such as faces, recognition and OCR is opt-in (P6);
  • galleries are a Stack, with Grid one tap away (G11);
  • swipe, hold and multi-select come from the row registry (#470).

Grill PH1–PH20 in chat.

kayg (2026-10-16): start the Photos feature, grill-first. Architecture and design only; mockups allowed, no implementation yet. Already decided elsewhere: - files live in `Photos/YYYY/YYYY-MM-DD/` (G12); - XMP sidecars hold metadata, Archive and Hide (#412); - devices keep thumbnails always and originals on demand or pinned (ADR 0046); - expensive work such as faces, recognition and OCR is opt-in (P6); - galleries are a Stack, with Grid one tap away (G11); - swipe, hold and multi-select come from the row registry (#470). Grill PH1–PH20 in chat.
Author
Owner

Research started for Photos issue #505. This is research only; branch: none. Base reference: local dev at a0785f1067. I will post sourced findings and the final stack recommendation here.

Research started for Photos issue #505. This is research only; branch: none. Base reference: local dev at a0785f1067c617755fbb00605aa0d5bb39163569. I will post sourced findings and the final stack recommendation here.
Author
Owner

Viewer reference (kayg, 2026-10-16): a native photos-app recording is in scratchpad/vid4/ref-viewer.mp4 (not in the repo).

  • Swipe up: the photo slides up and stays visible on top, and an info sheet rises with actions, caption, date, filename, camera, lens, exposure, a map and place, keywords and the source app.
  • Swipe down: the photo shrinks and flies back into its grid cell.

Take the interaction as inspiration only. kayg wants the metadata card itself clearly improved. Proposal for the mockup:

  • Hierarchy: the place and time come first, as a headline; camera and exposure become one quiet line of chips (ISO · mm · EV · f/ · s); file details (resolution, size, format) are tucked in a one-tap "File" row.
  • Calternal-first:
    • "In notes" (linked here), with "Add to note" and "New note with this";
    • albums (Views) as chips;
    • people and things (when those plugins are on);
    • recognised text (OCR) that can be copied.
  • Map: with "Open in Apple Maps / Google Maps".
  • Captions and keywords: written to XMP, editable inline.
  • The sheet: the shared glass, detents (half and full), springy; the photo stays visible and pans to keep its subject in view.
**Viewer reference (kayg, 2026-10-16):** a native photos-app recording is in scratchpad/vid4/ref-viewer.mp4 (not in the repo). - **Swipe up:** the photo slides up and stays visible on top, and an info sheet rises with actions, caption, date, filename, camera, lens, exposure, a map and place, keywords and the source app. - **Swipe down:** the photo shrinks and flies back into its grid cell. Take the interaction as inspiration only. kayg wants the metadata card itself clearly improved. Proposal for the mockup: - **Hierarchy:** the place and time come first, as a headline; camera and exposure become one quiet line of chips (ISO · mm · EV · f/ · s); file details (resolution, size, format) are tucked in a one-tap "File" row. - **Calternal-first:** - "In notes" (linked here), with "Add to note" and "New note with this"; - albums (Views) as chips; - people and things (when those plugins are on); - recognised text (OCR) that can be copied. - **Map:** with "Open in Apple Maps / Google Maps". - **Captions and keywords:** written to XMP, editable inline. - **The sheet:** the shared glass, detents (half and full), springy; the photo stays visible and pans to keep its subject in view.
Author
Owner

Finding 1 — image decoding speed and HEIC security

For common formats, a Rust image path is reasonable; use image 0.25.10 or zune-image 0.5.0, decode once, and derive all three sizes from one decoded image. For supported HEIC stills, zune-heic 0.5.0 is safe Rust and its maintainers report 84.2 ms for a 4284×5712 image on an M3 Pro versus 202.7 ms with libheif. That is a maintainer benchmark, not an independent 24 MP three-thumbnail test; zune-heic supports a limited subset and does not replace PhotoKit resource enumeration. image, zune-heic benchmark and limits.

Keep every decoder out of the API process. Examples include CVE-2026-32740 in libheif and CVE-2026-33165 in libde265; upstream also documented a working code execution exploit against libheif 1.23.1. The current upstream releases found today are libheif 1.23.6 and libde265 1.1.3. CVE-2026-32740, CVE-2026-33165, libheif advisory, libheif releases, libde265 releases.

Planning only, since no apples-to-apples 24 MP benchmark exists: 3 WebP sizes about 0.15–0.6 s and 100–250 MB per job; AVIF about 0.7–3 s and 150–500 MB. A 24 MP decoded buffer alone is 72 MB RGB or 96 MB RGBA. libvips published 68 MB/0.08 s for a 6048×4032 thumbnail, with a pathological progressive JPEG using 4 GB/4.3 s. libvips benchmark.

Finding 1 — image decoding speed and HEIC security For common formats, a Rust image path is reasonable; use image 0.25.10 or zune-image 0.5.0, decode once, and derive all three sizes from one decoded image. For supported HEIC stills, zune-heic 0.5.0 is safe Rust and its maintainers report 84.2 ms for a 4284×5712 image on an M3 Pro versus 202.7 ms with libheif. That is a maintainer benchmark, not an independent 24 MP three-thumbnail test; zune-heic supports a limited subset and does not replace PhotoKit resource enumeration. [image](https://docs.rs/image/latest/image/), [zune-heic benchmark and limits](https://docs.rs/zune-heic/latest/zune_heic/). Keep every decoder out of the API process. Examples include CVE-2026-32740 in libheif and CVE-2026-33165 in libde265; upstream also documented a working code execution exploit against libheif 1.23.1. The current upstream releases found today are libheif 1.23.6 and libde265 1.1.3. [CVE-2026-32740](https://nvd.nist.gov/vuln/detail/cve-2026-32740), [CVE-2026-33165](https://security-tracker.debian.org/tracker/CVE-2026-33165), [libheif advisory](https://github.com/strukturag/libheif/security/advisories/GHSA-2jg2-4ch7-h545), [libheif releases](https://github.com/strukturag/libheif/releases), [libde265 releases](https://github.com/strukturag/libde265/releases). Planning only, since no apples-to-apples 24 MP benchmark exists: 3 WebP sizes about 0.15–0.6 s and 100–250 MB per job; AVIF about 0.7–3 s and 150–500 MB. A 24 MP decoded buffer alone is 72 MB RGB or 96 MB RGBA. libvips published 68 MB/0.08 s for a 6048×4032 thumbnail, with a pathological progressive JPEG using 4 GB/4.3 s. [libvips benchmark](https://www.libvips.org/API/8.17/developer-checklist.html).
Author
Owner

Finding 2 — video posters

Use pinned LGPL-only FFmpeg/ffprobe as subprocesses in the same isolated media worker. ffmpeg seeks to a nearby keyframe; accurate seeking then decodes and discards intervening frames, so a cold arbitrary HEVC clip, especially long-GOP, has no reliable under-200-ms guarantee. Hit that target with an embedded still or cached poster; otherwise bound CPU, memory, one thread, and wall time. Keep hardware Vulkan decode off by default; FFmpeg 8.0 through 8.1.2 had CVE-2026-64831 in its HEVC Vulkan decoder. FFmpeg seek docs, FFmpeg licence, CVE-2026-64831.

Finding 2 — video posters Use pinned LGPL-only FFmpeg/ffprobe as subprocesses in the same isolated media worker. ffmpeg seeks to a nearby keyframe; accurate seeking then decodes and discards intervening frames, so a cold arbitrary HEVC clip, especially long-GOP, has no reliable under-200-ms guarantee. Hit that target with an embedded still or cached poster; otherwise bound CPU, memory, one thread, and wall time. Keep hardware Vulkan decode off by default; FFmpeg 8.0 through 8.1.2 had CVE-2026-64831 in its HEVC Vulkan decoder. [FFmpeg seek docs](https://www.ffmpeg.org/ffmpeg.html), [FFmpeg licence](https://github.com/FFmpeg/FFmpeg/blob/master/LICENSE.md), [CVE-2026-64831](https://nvd.nist.gov/vuln/detail/CVE-2026-64831).
Author
Owner

Finding 3 — Apple resources must be uploaded as an asset graph

Do not treat a Photos selection as one file. Enumerate PHAssetResource.assetResources(for:) and upload each resource unchanged with its resource type, filename/UTI, hash, asset ID, and pair links. Depending on the device and edit history this can include HEIC and depth/matte data, ProRAW DNG, Live Photo paired MOV, spatial media, Cinematic video and metadata, slow-motion/time-lapse movies, full-size edited renders, and adjustment/base resources. Use PhotoKit’s pairedVideo relationship and retain the Live Photo ContentIdentifier; request bytes via PHAssetResourceManager and allow iCloud download when needed. Apple’s iOS 27 background resource upload job API can schedule per-resource uploads. PHAssetResourceType, PHAssetResourceManager, paired video, Live Photo metadata, iOS background upload.

Immich issues show two failure examples for file-level flows: separate web uploads not paired as a Live Photo, and background upload leaving an incomplete pair. These are issue-specific reports, but they illustrate why the client should send the asset graph. web flow, background upload.

Finding 3 — Apple resources must be uploaded as an asset graph Do not treat a Photos selection as one file. Enumerate PHAssetResource.assetResources(for:) and upload each resource unchanged with its resource type, filename/UTI, hash, asset ID, and pair links. Depending on the device and edit history this can include HEIC and depth/matte data, ProRAW DNG, Live Photo paired MOV, spatial media, Cinematic video and metadata, slow-motion/time-lapse movies, full-size edited renders, and adjustment/base resources. Use PhotoKit’s pairedVideo relationship and retain the Live Photo ContentIdentifier; request bytes via PHAssetResourceManager and allow iCloud download when needed. Apple’s iOS 27 background resource upload job API can schedule per-resource uploads. [PHAssetResourceType](https://developer.apple.com/documentation/photos/phassetresourcetype), [PHAssetResourceManager](https://developer.apple.com/documentation/photos/phassetresourcemanager), [paired video](https://developer.apple.com/documentation/photos/phassetresourcetype/pairedvideo), [Live Photo metadata](https://developer.apple.com/documentation/avfoundation/avcapturephotosettings/livephotomoviemetadata?language=objc), [iOS background upload](https://developer.apple.com/documentation/photokit/uploading-asset-resources-in-the-background). Immich issues show two failure examples for file-level flows: separate web uploads not paired as a Live Photo, and background upload leaving an incomplete pair. These are issue-specific reports, but they illustrate why the client should send the asset graph. [web flow](https://github.com/immich-app/immich/issues/1623), [background upload](https://github.com/immich-app/immich/issues/22601).
Author
Owner

Finding 4 — optional CPU plugins and rights

OCR: PP-OCRv6 tiny is the server recommendation as an opt-in ONNX worker; the publisher reports 0.20 s end-to-end on Xeon 8350C with OpenVINO, and its internal tiny metrics are 80.6 detection Hmean / 73.5 recognition average accuracy. These are publisher metrics, not general photo accuracy. Apple Vision is a client-side alternative. PP-OCRv6, Apple Vision.

Tags and semantic search: quantized SigLIP2 base patch16/224 in ONNX provides image/text embeddings and curated zero-shot tags; its model card is Apache-2.0. CLIP’s own model card says it was not built for general deployment. RAM++ is a possible open-set tagger, but its checkpoint terms are not clear enough to bundle yet. SigLIP2, CLIP model card, RAM++ model zoo.

Faces: opt-in YuNet + SFace has MIT/Apache-2.0 model-directory licences and small CPU costs; review SFace training-data provenance. InsightFace code is MIT, but its public pretrained recognition weights are non-commercial research only without another licence. Store regions in XMP mwg-rs and use Calternal’s own stable person UUID. YuNet, SFace, InsightFace model licence, MWG guidelines.

Geocoding: GeoNames cities500 is 13 MB compressed and CC-BY 4.0; optional regional OSM neighborhood points add labels such as Delhi Aerocity but bring ODbL obligations. Use a Rust 2D k-d tree. GeoNames size/licence, OSM attribution, kiddo.

Finding 4 — optional CPU plugins and rights OCR: PP-OCRv6 tiny is the server recommendation as an opt-in ONNX worker; the publisher reports 0.20 s end-to-end on Xeon 8350C with OpenVINO, and its internal tiny metrics are 80.6 detection Hmean / 73.5 recognition average accuracy. These are publisher metrics, not general photo accuracy. Apple Vision is a client-side alternative. [PP-OCRv6](https://github.com/PaddlePaddle/PaddleOCR/blob/main/docs/version3.x/algorithm/PP-OCRv6/PP-OCRv6.en.md), [Apple Vision](https://developer.apple.com/documentation/vision/recognizing_text_in_images). Tags and semantic search: quantized SigLIP2 base patch16/224 in ONNX provides image/text embeddings and curated zero-shot tags; its model card is Apache-2.0. CLIP’s own model card says it was not built for general deployment. RAM++ is a possible open-set tagger, but its checkpoint terms are not clear enough to bundle yet. [SigLIP2](https://huggingface.co/google/siglip2-base-patch16-224), [CLIP model card](https://github.com/openai/CLIP/blob/main/model-card.md), [RAM++ model zoo](https://github.com/xinyu1205/recognize-anything/blob/main/README.md). Faces: opt-in YuNet + SFace has MIT/Apache-2.0 model-directory licences and small CPU costs; review SFace training-data provenance. InsightFace code is MIT, but its public pretrained recognition weights are non-commercial research only without another licence. Store regions in XMP mwg-rs and use Calternal’s own stable person UUID. [YuNet](https://github.com/opencv/opencv_zoo/tree/main/models/face_detection_yunet), [SFace](https://github.com/opencv/opencv_zoo/tree/main/models/face_recognition_sface), [InsightFace model licence](https://github.com/deepinsight/insightface/tree/master/python-package/docs), [MWG guidelines](https://onefolder.app/mwg.pdf). Geocoding: GeoNames cities500 is 13 MB compressed and CC-BY 4.0; optional regional OSM neighborhood points add labels such as Delhi Aerocity but bring ODbL obligations. Use a Rust 2D k-d tree. [GeoNames size/licence](https://download.geonames.org/export/dump/readme.txt), [OSM attribution](https://www.openstreetmap.org/copyright), [kiddo](https://docs.rs/kiddo/latest/kiddo/).
Author
Owner

Photos research complete

Stage Recommended stack
Decode image 0.25.10 for common formats; zune-heic 0.5.0 for its supported primary HEIC stills; patched libheif 1.23.6/libde265 1.1.3 only in the isolated fallback. image, zune-heic limits/benchmark, libheif, libde265.
Thumbnails Three WebP sizes by default; AVIF is opt-in due CPU cost. Estimated 0.15–0.6 s and 100–250 MB per 24 MP WebP job; AVIF 0.7–3 s and 150–500 MB. No apples-to-apples public 24 MP three-size benchmark was found. libvips benchmark, AVIF benchmark.
Video Rust container crates are fine for metadata-only probing; use LGPL-only FFmpeg/ffprobe for broad software HEVC decode and posters. A cached or embedded poster can meet 200 ms; arbitrary HEVC cannot be guaranteed because seeking decodes from a keyframe. seek docs, codec support, licence.
Apple originals Upload every PhotoKit PHAssetResource unchanged with resource type, hash, asset UUID, and pair links. This preserves HEIC depth/mattes, ProRAW DNG, Live Photo MOV pairs, edits/adjustment data, spatial/Cinematic media, and slow motion/time-lapse resources. Use iOS 27 per-resource background upload when available. resource types, resource manager, paired video, background upload.
OCR Opt-in PP-OCRv6 tiny via ONNX Runtime; Apple Vision is a client-side option. Published tiny OpenVINO benchmark is 0.20 s on Xeon 8350C; accuracy metrics are publisher internal-set results. PP-OCRv6, Vision.
Tags/search Opt-in quantized SigLIP2 base patch16/224 ONNX for curated tags plus image/text embeddings. RAM++ checkpoint terms need review; CLIP’s model card cautions against general deployment. SigLIP2, RAM++, CLIP model card.
Faces Opt-in YuNet + SFace after model provenance review; write XMP MWG regions and a stable Calternal person UUID. InsightFace code is MIT but public pretrained ArcFace weights such as buffalo_l are non-commercial absent a separate licence. YuNet, SFace, InsightFace model terms, MWG guidelines.
Reverse geocoding GeoNames cities500 (13 MB compressed, CC-BY 4.0) plus optional regional OSM neighborhood points (ODbL), indexed with a Rust k-d tree. GeoNames, OSM terms, kiddo.

Isolation: run decoders, ffprobe, and FFmpeg in a short-lived unprivileged worker with a separate UID, no network/capabilities/devices, closed inherited FDs, and only the input FD plus bounded scratch/output. Restrict paths with Landlock and syscalls with seccomp; cap CPU, memory, PIDs, pixels, bytes, and wall time. Landlock, seccomp. Recent parser issues include CVE-2026-32740, CVE-2026-33165, and an upstream libheif code-execution advisory.

Resource model: keep one decoder active on 4 cores and at most two on 14 cores; queue IDs, bound queue size, start plugin workers on demand, unload after idle. Estimates for 50k 24 MP photos: WebP 0.5–2.1 h with ideal four-way scaling; optional tags add 0.35–2.1 h, OCR 0.7–2.8 h, and AVIF 2.4–10.4 h. These are planning estimates, not Calternal measurements. The Rust server can stay near its 14 MB idle RSS when codec/model workers are separate.

Full source report: /home/kayg/Developer/calternal-research/photos-2026-10-16.md

Branch: none. Base/head reference: local dev SHA a0785f1067.
Gate output: not run (research-only; no code change).

## Photos research complete | Stage | Recommended stack | |---|---| | Decode | image 0.25.10 for common formats; zune-heic 0.5.0 for its supported primary HEIC stills; patched libheif 1.23.6/libde265 1.1.3 only in the isolated fallback. [image](https://docs.rs/image/latest/image/), [zune-heic limits/benchmark](https://docs.rs/zune-heic/latest/zune_heic/), [libheif](https://github.com/strukturag/libheif/releases), [libde265](https://github.com/strukturag/libde265/releases). | | Thumbnails | Three WebP sizes by default; AVIF is opt-in due CPU cost. Estimated 0.15–0.6 s and 100–250 MB per 24 MP WebP job; AVIF 0.7–3 s and 150–500 MB. No apples-to-apples public 24 MP three-size benchmark was found. [libvips benchmark](https://www.libvips.org/API/8.17/developer-checklist.html), [AVIF benchmark](https://github.com/strukturag/libheif/wiki/AVIF-Encoder-Benchmark). | | Video | Rust container crates are fine for metadata-only probing; use LGPL-only FFmpeg/ffprobe for broad software HEVC decode and posters. A cached or embedded poster can meet 200 ms; arbitrary HEVC cannot be guaranteed because seeking decodes from a keyframe. [seek docs](https://www.ffmpeg.org/ffmpeg.html), [codec support](https://ffmpeg.org/ffmpeg-codecs.html), [licence](https://github.com/FFmpeg/FFmpeg/blob/master/LICENSE.md). | | Apple originals | Upload every PhotoKit PHAssetResource unchanged with resource type, hash, asset UUID, and pair links. This preserves HEIC depth/mattes, ProRAW DNG, Live Photo MOV pairs, edits/adjustment data, spatial/Cinematic media, and slow motion/time-lapse resources. Use iOS 27 per-resource background upload when available. [resource types](https://developer.apple.com/documentation/photos/phassetresourcetype), [resource manager](https://developer.apple.com/documentation/photos/phassetresourcemanager), [paired video](https://developer.apple.com/documentation/photos/phassetresourcetype/pairedvideo), [background upload](https://developer.apple.com/documentation/photokit/uploading-asset-resources-in-the-background). | | OCR | Opt-in PP-OCRv6 tiny via ONNX Runtime; Apple Vision is a client-side option. Published tiny OpenVINO benchmark is 0.20 s on Xeon 8350C; accuracy metrics are publisher internal-set results. [PP-OCRv6](https://github.com/PaddlePaddle/PaddleOCR/blob/main/docs/version3.x/algorithm/PP-OCRv6/PP-OCRv6.en.md), [Vision](https://developer.apple.com/documentation/vision/recognizing_text_in_images). | | Tags/search | Opt-in quantized SigLIP2 base patch16/224 ONNX for curated tags plus image/text embeddings. RAM++ checkpoint terms need review; CLIP’s model card cautions against general deployment. [SigLIP2](https://huggingface.co/google/siglip2-base-patch16-224), [RAM++](https://github.com/xinyu1205/recognize-anything/blob/main/README.md), [CLIP model card](https://github.com/openai/CLIP/blob/main/model-card.md). | | Faces | Opt-in YuNet + SFace after model provenance review; write XMP MWG regions and a stable Calternal person UUID. InsightFace code is MIT but public pretrained ArcFace weights such as buffalo_l are non-commercial absent a separate licence. [YuNet](https://github.com/opencv/opencv_zoo/tree/main/models/face_detection_yunet), [SFace](https://github.com/opencv/opencv_zoo/tree/main/models/face_recognition_sface), [InsightFace model terms](https://github.com/deepinsight/insightface/tree/master/python-package/docs), [MWG guidelines](https://onefolder.app/mwg.pdf). | | Reverse geocoding | GeoNames cities500 (13 MB compressed, CC-BY 4.0) plus optional regional OSM neighborhood points (ODbL), indexed with a Rust k-d tree. [GeoNames](https://download.geonames.org/export/dump/readme.txt), [OSM terms](https://www.openstreetmap.org/copyright), [kiddo](https://docs.rs/kiddo/latest/kiddo/). | Isolation: run decoders, ffprobe, and FFmpeg in a short-lived unprivileged worker with a separate UID, no network/capabilities/devices, closed inherited FDs, and only the input FD plus bounded scratch/output. Restrict paths with Landlock and syscalls with seccomp; cap CPU, memory, PIDs, pixels, bytes, and wall time. [Landlock](https://docs.kernel.org/userspace-api/landlock.html), [seccomp](https://docs.kernel.org/userspace-api/seccomp_filter.html). Recent parser issues include [CVE-2026-32740](https://nvd.nist.gov/vuln/detail/cve-2026-32740), [CVE-2026-33165](https://security-tracker.debian.org/tracker/CVE-2026-33165), and an upstream [libheif code-execution advisory](https://github.com/strukturag/libheif/security/advisories/GHSA-2jg2-4ch7-h545). Resource model: keep one decoder active on 4 cores and at most two on 14 cores; queue IDs, bound queue size, start plugin workers on demand, unload after idle. Estimates for 50k 24 MP photos: WebP 0.5–2.1 h with ideal four-way scaling; optional tags add 0.35–2.1 h, OCR 0.7–2.8 h, and AVIF 2.4–10.4 h. These are planning estimates, not Calternal measurements. The Rust server can stay near its 14 MB idle RSS when codec/model workers are separate. Full source report: /home/kayg/Developer/calternal-research/photos-2026-10-16.md Branch: none. Base/head reference: local dev SHA a0785f1067c617755fbb00605aa0d5bb39163569. Gate output: not run (research-only; no code change).
Author
Owner

Proposed ADR for Photos: 0050 Photos: originals, sidecars and processing, in PR #561 (docs only, don't merge until kayg says so). It covers the storage layout, XMP sidecars, grouping (including the time-based Live Photo fallback), thumbnails, the sandboxed worker, ML, vectors (the 200k gate), geocoding, imports, uploads, the 120 fps timeline, the versions to pin, and the open checks. Open questions with recommended answers are in the ADR.

Proposed ADR for Photos: **0050 Photos: originals, sidecars and processing**, in PR #561 (docs only, don't merge until kayg says so). It covers the storage layout, XMP sidecars, grouping (including the time-based Live Photo fallback), thumbnails, the sandboxed worker, ML, vectors (the 200k gate), geocoding, imports, uploads, the 120 fps timeline, the versions to pin, and the open checks. Open questions with recommended answers are in the ADR.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
kayg/calternal#505
No description provided.