8000 fix: distant photos, upload pixel limit, crop warning and unreachable-server errors by jasonmadigan · Pull Request #247 · tracefinity/tracefinity · GitHub
[go: up one dir, main page]

Skip to content

fix: distant photos, upload pixel limit, crop warning and unreachable-server errors - #247

Merged
jasonmadigan merged 4 commits into
mainfrom
fix/244-corner-step-pixel-limit
Nov 10, 2026
Merged

jasonmadigan merged 4 commits into
mainfrom
fix/244-corner-step-pixel-limit

Conversation

@jasonmadigan
@jasonmadigan jasonmadigan commented Nov 10, 2026 •
Copy link
Copy Markdown
Collaborator

Summary

Four fixes for what #244 ran into, one commit each.

1. Distant photos rejected at the corner step

The corner step drew the whole visible frame at 10 px/mm, then shrank it to the stored 2048 px. That intermediate grows as the sheet shrinks in the photo, and the upload pixel limit was applied to it. A sheet filling a quarter of the frame comes to over 100 megapixels, so the photo was rejected with the oversized-upload message, image has N pixels; maximum is 64,000,000. A 24 to 26 mm phone camera reaches that at about 64 to 69 cm, inside the 60 cm or higher the photo warning asks for.

 set_corners
   check_photo
   apply_perspective_correction
-    warp the visible frame at 10 px/mm          # 120 MP for a quarter-frame sheet
-    write it out
-  ingest_image(corrected)
-    413 if pixels > MAX_IMAGE_PIXELS
-    decode, shrink to 2048 px, encode again
-  scale_factor /= shrink ratio
+    warp the visible frame at the stored size   # long edge 2048 px
+    encode once
+    return mm per px at that size

2. Pixel limit checked late, and capped by Pillow

 upload_image
-  extract_focal_length_35mm(upload)   # Pillow decodes a whole PNG to find its EXIF
   ingest_image(upload)
+    lift Pillow's own cap to MAX_IMAGE_PIXELS when that is higher
     413 if pixels > MAX_IMAGE_PIXELS
+  extract_focal_length_35mm(upload)

An oversized PNG was decoded in full before it was rejected. Separately, Pillow refuses anything above about 179 megapixels, so a higher MAX_IMAGE_PIXELS never took effect.

3. Camera distance warning on cropped photos

The estimate treats the image as the whole frame the camera took. A cropped photo keeps its focal length, so the camera reads closer by the crop factor. A capture crop is now undone before estimating, and the check is skipped when the EXIF pixel size differs from the file's, as after a crop or resize elsewhere. An editor that rewrites the EXIF size still hides the crop.

4. Unreachable server shown as "request failed"

When the backend is down, still starting, killed or slow, nginx answers with an HTML error page. The frontend showed each as request failed, rendered the app as if it were healthy, and nginx wrote the reason to a file inside the container.

 throwApiError
-  no detail in the body: "request failed"
+  no detail in the body: "server unavailable (HTTP 502)", "server timed out (HTTP 504)",
+                         "file too large for the server (HTTP 413)", "request failed (HTTP nnn)"
 <AuthGate>
+  auth status fails with a network error or 5xx:
+    <Alert> Can't reach the Tracefinity server (HTTP 502). It may still be starting. ...
+    retry every 5 s until it answers
   {children}
 nginx
-  error_log /var/log/nginx/error.log
+  error_log stderr                    # reaches the container log

User-visible changes

  • Photos with a small sheet in frame pass the corner step with default settings.
  • The corrected image is resampled and encoded once instead of twice. Dimensions and format are the same; the scale factor moves by under 0.01%.
  • Oversized uploads are rejected before decoding, and MAX_IMAGE_PIXELS above about 179 megapixels takes effect.
  • The camera distance warning no longer appears for a photo whose EXIF size differs from the file, including a resized one, and is right under a capture crop.
  • Errors without a server detail name their HTTP status. The app shows an alert while the server cannot be reached.
  • nginx errors appear in the container log.

Relates to #244. What made the request fail there after MAX_IMAGE_PIXELS was raised is not established; 1 removes the need to raise it and 4 makes that kind of failure readable.

Evidence

Before is the 0.10.1 image, after is an image built from this branch.

  1. Photo attached to MAX_IMAGE_PIXELS > 64k results in "request failed" #244 (3072x4096, sheet about a quarter of the frame), default settings, POST /api/sessions/{id}/corners:
    • Before: 413 {"detail":"image has 119,961,898 pixels; maximum is 64,000,000"}. With MAX_IMAGE_PIXELS=200000000: 200 in 0.92 s, container memory peaking at 1.44 GiB against 0.72 GiB idle.
      After: 200 in 0.04 s, 1781x2048 at 0.5735 mm/px. Against the 0.10.1 output for the same corners: same dimensions, mean absolute difference 1.0/255, scale factor 0.006% apart.
    • Resampling once instead of twice was also compared, as a one-off outside the suite, against an ideal top-down render of five synthetic scenes including extreme keystone. An 80 x 30 mm object measured within 0.05 mm of the old pipeline's result in each.
  2. A 450 KB, 144 megapixel PNG, default settings, POST /api/upload:
    • Before: 413 after 0.92 s, container memory peak up 535 MiB.
      After: 413 after 0.01 s, peak unchanged.
    • A 196 megapixel PNG with MAX_IMAGE_PIXELS=400000000. Before: 413 {"detail":"image dimensions exceed the configured limit"}. After: 200.
  3. The two photos attached to MAX_IMAGE_PIXELS > 64k results in "request failed" #244 give height estimates 3.63 times apart for the same shot; the crop factor between them is 3.65.
    • Before: a sheet shot from 70 cm and kept as the centre half by a capture crop warned Camera looks about 35 cm from the paper.
      After: no warning. A photo with EXIF size 3072x4096 in an 887x1089 file stores no focal length.
    • frontend/e2e/fixtures/tool.jpg is a real case: EXIF records 5712x4284, the file is 3890x5047.
  4. Container started with a backend that cannot start:
    • Before: the app renders normally, an upload shows request failed, the container log has no line for the 502.
      After: the alert above shows, an upload shows server unavailable (HTTP 502), and the container log carries nginx's connect() failed (111: Connection refused) while connecting to upstream under the default user, --user and PUID/PGID.
    • On a normal start the alert shows while the backend boots (about 20 to 30 s here), then clears and the app routes to /setup. Checked in Chromium, light and dark.

Tests added: 7 for the corner step, 3 for the pixel limit, 9 for the camera distance check, 24 for the frontend. Those for new behaviour were watched failing first.

Ran on Python 3.12.10, Pillow 13.0.0, OpenCV 5.0.0, Node 22.20.0:

  • make lint: passed, 9 existing frontend warnings
  • cd backend && venv/bin/python -m pytest: 871 passed
  • cd frontend && pnpm test: 299 passed
  • make test-e2e-accuracy: 5 passed
  • make test-e2e: 23 passed
  • docker build, then tests/test_entrypoint.sh in the image: 16 passed

Merge Danger

Door: two-way. No stored data changes shape; each commit reverts on its own.

Blast Radius: calibration. Every traced outline is scaled by the mm per px the corner step returns, so an error there would scale every new trace wrongly. The photo-to-STL size tests (8 cases within 1 mm) and the browser accuracy suite cover that path. The other three are narrower: upload acceptance, one advisory warning, and error text plus container logging.

The corner step rendered the whole visible frame at 10 px/mm and then
shrank it to the stored size. That intermediate grows as the sheet
shrinks in the photo: a sheet filling a quarter of the frame is over
100 megapixels. The upload pixel limit was applied to it as well, so
those photos were rejected with "image has N pixels; maximum is
64,000,000". With the limit raised the step held the intermediate in
memory twice, about 0.7 GB for 120 megapixels.

Warp straight to the stored size and return the matching scale. The
upload pixel limit now covers uploaded photos and masks only.

Relates to #244

Signed-off-by: Jason Madigan <jason@jasonmadigan.com>
Reading the focal length ran before the pixel limit. Pillow decodes a
whole PNG to look for its EXIF, so a 450 KB, 144 megapixel PNG cost
about 580 MB before it was rejected. The limit is now checked first.

Pillow also refuses any image above twice its own cap, about 179
megapixels, so a MAX_IMAGE_PIXELS above that never took effect.
ingest_image now lifts that cap to a higher configured limit. It never
lowers it, since stored images outgrow a small upload limit.

Relates to #244

Signed-off-by: Jason Madigan <jason@jasonmadigan.com>
… frame

The estimate treats the image as the whole frame the camera took. A
cropped photo keeps its focal length, so the sheet looks larger on the
sensor than it was and the camera reads closer by the crop factor, 3.6
times for the photo in #244.

A capture crop is now undone before estimating. A photo whose EXIF
records a different pixel size than the file has was cropped or resized
after capture, and the check is skipped for it. An editor that rewrites
the EXIF size still hides the crop.

Relates to #244

Signed-off-by: Jason Madigan <jason@jasonmadigan.com>
When the backend is down, still starting, killed or slow, nginx answers
with an HTML error page. The frontend showed every such response as
"request failed" and rendered the app as if it were healthy, while
nginx wrote the reason to a file inside the container.

Error responses without a detail now name their HTTP status. The app
shell shows an alert while the auth status check fails with a network
error or a 5xx, and retries every five seconds until it clears. nginx
logs errors to stderr, so they reach the container log.

Relates to #244

Signed-off-by: Jason Madigan <jason@jasonmadigan.com>
@jasonmadigan jasonmadigan changed the title fix: accept photos where the sheet fills little of the frame fix: distant photos, upload pixel limit, crop warning and unreachable-server errors Nov 10, 2026
@jasonmadigan
jasonmadigan marked this pull request as ready for review November 10, 2026 15:32
@jasonmadigan
jasonmadigan merged commit c656db2 into main Nov 10, 2026
6 checks passed
@jasonmadigan
jasonmadigan deleted the fix/244-corner-step-pixel-limit branch November 10, 2026 17:16
@jasonmadigan jasonmadigan linked an issue Nov 10, 2026 that may be closed by this pull request
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.

MAX_IMAGE_PIXELS > 64k results in "request failed"

1 participant

0