Review of the compression branch (ce93c68..d7c1415): one Important and the
cheap real Minors, each with a RED test first.
- app.py: drop the manual Content-Length override - it broke ranged
requests (206 announcing the full length while sending a slice).
send_file sets it and the 206/Content-Range itself.
- app.py: the download route serves video extensions only, never the temp
of an encode in flight.
- src/compress.py: the encode temp is unique per attempt (mkstemp), is
validated (playable video) and fsynced before it replaces the original;
a failing os.replace keeps the original and cleans the temp up instead
of raising into the route. The compressed video keeps the source mode.
- src/compress.py: a stale temp of a killed encode is swept after 2 h
instead of the 5-day video expiry.
- src/job.py: cancelled and failed jobs are not re-encoded; the job shows
"Compressing..." while the encode runs.
- ERD.md: the $OUTPUT_DIR/*_compressed.mp4 row is gone.
328 tests pass (was 319).
CHANGELOG: a finished job leaves one compressed video (compressed in place
under the plain name) and the job videos expire after 5 days.
README: the output lifecycle - one video per job, 5-day retention.
Plan: the implementation plan this branch followed.
The annotated output was kept uncompressed forever: a 20-minute clip left
a 724 MB file in output/job-*/, and the download route wrote a second
"_compressed.mp4" next to it (both kept).
Now the job compresses its own output when it finishes: the encode goes to
a temp file, is validated, and replaces the source atomically
(os.replace) under the SAME name. One video per job, the client never sees
a "_compressed" file, and the API's output_path stays valid. A failed
encode or a result that still overshoots the cap leaves the original
untouched, so nothing is ever lost.
The job videos are deleted 5 days after the job (scripts/purge_expired_
outputs.py, cron daily 03:17); the job dir, the thumbnail and the sample
frames stay, so the jobs list still renders.
CHANGELOG: the same-class dedup dropped overlapping sacks (FCP keeps every
tracked detection) - published counts increase, the 20-minute test clip now
reports the same 161 in / 1 out as FCP.
Plan: Task 14 (dedup across models only) and the full-clip cross-check
result (161 / 1 / 160 on both sides).
The merged pipeline ran a same-class IoU-0.5 dedup over ALL detections,
including the primary model's own tracked detections. FCP keeps every
tracked detection - the detector's own NMS already removed the duplicates
inside a model (predict.py:891). Two sacks stacked on the truck overlap by
more than IoU 0.5, so the recounter dropped one of them and lost its
crossing: 54 detections dropped in 400 frames of the test clip, and 3
fewer sacks than FCP on the 20-minute clip (158 vs 161).
The dedup now compares only detections from DIFFERENT models, and the
tracked primary always wins: an extra carries a synthetic track id, and
swapping the id would lose the track's crossing history.
The status page showed "Batches: 0" for a clip with an open batch, which
reads like "no batch was counted". The number is the count of FINISHED
batches, so say so.
Plan: record the FCP cross-check that was run on this box (a 60 s excerpt,
model mode C: FCP 6/0/6 vs the recounter 6/0/6 - the same counts) with the
exact commands.
Plan: add Task 12 (a broken zone calibration degrades instead of publishing
a wrong count) and Task 13 (FCP's batch lifecycle — count every frame, the
FSM's arguments, a real truck signal), update the file structure and the
verification steps, and record the two remaining gaps as out of scope (the
dynamic-mode counting line, the truncated flag in the UI).
CHANGELOG: the batch-lifecycle change (published counts and batch_count can
change for every clip), the zone-calibration hardening and the review-wave
fixes.
The fixed-mode truck signal accepted any truck in the frame; FCP keeps a
truck only when at least 50% of its bbox overlaps the detection polygon
and uses that as the batch's truck signal (predict.py:964).
The whole-branch review found three ways a broken zones.json could reach a
published count:
- build_static_roi indexed the truck_area points directly, so a 1-element
point (IndexError) or an infinite coordinate (OverflowError) escaped the
app's guard and became a 500. It now reuses _scaled_points and raises
ValueError, which the guard already handles.
- A missing or short truck_area fell back to an invented heuristic box that
was still published as a calibrated "fixed" zone. It now degrades to
dynamic mode instead.
- A degenerate (zero-area) counting polygon was built successfully and
filtered out every detection, silently publishing zero counts. It is
now rejected like any other malformed calibration.
Also: the app guard catches IndexError/KeyError/OverflowError, the zone
preset comment no longer claims 1920x1080 coordinates are authored for
1280x720, and two FCP citations are corrected.
CHANGELOG: the thresholds, cadence, count-line window, batch lifecycle,
fail-fast config and truncation-flag changes, with their consequences for
the published counts. The Task 0 entry now says the annotated output is
1280x720 (an explicit output_height below 720 still downscales it).
Plan: add the Task 11 section (FCP's calibrated count-line x-window),
correct the Task 1 and Task 7 FCP citations, and refresh the file
structure and the verification snippet.
- zone_config: a count_line without x_start/x_end/y fell back to the
frame-space ROI bounds and scaled them a second time (400 -> 266).
- app: _resolve_fcp_mode answers JSON 400 when config.yaml is invalid
instead of raising through to a Flask 500.
- config: the DEFAULTS fallback (missing/empty config.yaml) is validated
like a real config, and a test pins DEFAULTS to the shipped config.yaml.
- job: add_job downgrades zone_mode "fixed" to "dynamic" when no calibrated
ROI was supplied — the label now matches what the job counts against.
- counting: correct the FCP citation (src/counting.py:171).
- tests: the analyze_env stub was missing the new result fields, so every
/upload job ended in FAILED; cover the truncation fields in both job
endpoints, /upload/reuse zone mode and the broken-config path.
Task 0 added to the FCP parity plan: the decoded frame is resized to
1280x720 before inference (FCP predict.py:826), imgsz=640 is passed
explicitly on every track()/predict() call (FCP predict.py:467), and the
annotated output is written at exactly 1280x720.
Consequences pinned in the plan: the static zone and the counting polygon
are scaled in FCP's frame (build_static_roi(zone, 1280, 720)), and
min_bbox_area becomes literal FCP px^2 (config_loader.py:67) instead of
a scaled approximation.
Also fixed the Verification snippet: TruckROI has no line_x_start /
line_x_end fields, so it printed an AttributeError; expected output is
now '220 400 936'. Baseline test count refreshed 195 -> 204.
Output was a fixed name (merged_annotated.mp4) so every download looked
the same. The source clip name is now appended at the back:
merged_annotated_rekap_2026-10-27.mp4
- src/naming.py: annotated_output_name() + source_stem(); client upload
name wins, stored file name is the fallback (reuse endpoint), unsafe
chars replaced, stem capped at 80 chars
- src/job.py: Job.source_stem + add_job(source_stem=...); both output
paths go through the helper
- app.py: capture the sanitized client filename before the collision
suffix is added
- cli.py: same helper for the CLI output name
Verified live on .93: POST /api/analyze with 'rekap 2026-10-27.mp4' ->
output/job-e0409b05/merged_annotated_rekap_2026-10-27.mp4, download 200.
Audit of karung_counter_semarang (FCP) vs feedmill_recounter found the
counting core only partially synced: the unload-after-load gate, the
counting-polygon centroid filter, the calibrated static count line,
sack conf 0.30, box min_bbox_area 1000, stabilizer max_hold 10 and
real batch-FSM crossing events were never ported. Plan lists 10
TDD tasks, each pinned to the FCP file:line it mirrors. FCP itself
is read-only.
Live E2E from .96: POST /api/analyze on 192.168.192.93:9050 -> 202 ->
job COMPLETED. Earlier 'firewall blocks everything' conclusion was
wrong: only ICMP ping is dropped; TCP works fine. Reverse tunnel was
built then reverted (e3a905e/cb483c0) per operator policy — doc now
records direct URL as the sanctioned path, with 401/409/400 handling
guidance and the real API key location.
ERD: no DB in this repo — models in-memory Job/JobResult entities plus
filesystem artifacts (uploads/, output/job-*/, zones.json, models/),
with status state machine and restart/orphan hazards.
CHANGELOG: Keep a Changelog format covering all 83 commits grouped by
date, from 2026-09-15 init through the /upload NameError 500 fix.
Previously, app.py:123-125 tried to use and
before was defined.
This caused NameError and 500 Internal Server Error when users uploaded
new videos and pressed 'start analysis'.
The code block (lines 122-125) was duplicate logic - the later transcoding
at line 138 already handles the height check.
Fixes: # (Issue reference not provided)
- src/preview.py: added resize_video_to_max_height() using ffmpeg
(tries nvenc/v4l2m2m then libx264, atomic overwrite, only if >720p)
- app.py upload: transcode to 720p immediately after save
- app.py upload_reuse: probe first, only transcode if height > 720p
- templates/index.html: 720p output checkbox checked by default
- zones already scale correctly via build_static_roi (reference 1920x1080 -> 720p)
- 177 tests pass
Jobs are in-memory; output/job-* dirs survived restarts but never
appeared in /jobs, leaving 5.2GB undeletable. JobQueue now registers
stale job-* dirs (>5min old) as COMPLETED ghosts so the existing delete
flow rmtree's them. register_orphans=False opt-out. 177 tests pass (+3).
Platform force-resizes frames to 1280x720 before detection, so its
1500/5000 px2 thresholds are authored in that space. Applying them raw
at native 1080p made recounter's effective bar 2.25x weaker — false
divergence in double-check runs. _scaled_min_areas scales by frame area
(1080p: 3375/11250, 720p: unchanged).
Platform's get_min_valid_area perspective gate is dead code (zero call
sites) — deliberately not ported, it would make recounter stricter than
platform. 174 tests pass (+1).
- _AsyncWriter: encode+draw overlap GPU inference (queue maxsize=2
backpressure, order-preserving, first error surfaced at close, never
masks original exception) — ~15-35% higher end-to-end FPS
- MJPEG endpoint yields only on preview mtime change instead of re-sending
the same JPEG every 50ms
- 173 tests pass (+5)
No load handler existed — placeholder overlay (absolute inset:0) stayed
on top of the live stream forever. Hide on img load; toggle OFF already
re-shows it.
Throttled tracking caused ByteTrack ID switches at crossings -> counter
re-initializes new tracks without counting -> lost In counts; sup=10 put
box holds one detection-miss from expiry. Defaults back to every-frame
tracking; params kept for opt-in throttling. 720p/preview gains kept.
- index.html: checked moves from dynamic to fixed radio; preset config
visible on load (was only added on change event)
- app.js: when no zone presets exist, fall back to dynamic radio + hide
preset config (server already falls back to dynamic)
- SyntheticIdAssigner: track_id=None dets get stable negative IDs so the
stabilizer hold bridges sup_det_interval gaps -> no flicker, boxes count
- apply primary model class filter in merged path (UI checkboxes work)
- _suppress_sacks_under_boxes: sack dets overlapping box dets dropped
(models without box class label boxes as sack; stops double counting)
- default web port 9000 -> 9050 (WEB_PORT env still overrides)
- README: port refs, counting zone modes section, project tree
- 140 tests pass (+13)
Tests imported the global job_queue (bound to real OUTPUT_DIR), creating
8 junk job-* dirs per pytest run (test_app x3, test_download_compress x4,
test_preview x1). Fixture redirects _output_dir to tmp_path and clears
the job registry before each test.