docs: update FCP handoff — direct .96→.93:9050 verified, tunnel reverted
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.
This commit is contained in:
1 parent
cb483c0824
commit
20f8b8f9e6
2 files changed
+96
-61
No files matched your search
@@ -18,6 +18,12 @@ version tags are cut in this repo — `main` is the release line).
|
||||
`{stem: engine_classes}`, mirroring platform `models.modes
|
||||
engines[].classes` exactly (B/D use v4-best truck-only role, not
|
||||
truck-detector weights).
|
||||
- **Network reality (verified 2026-10-20):** direct
|
||||
`http://192.168.192.93:9050/api/analyze` from the FCP host (.96) works
|
||||
(live 202 → COMPLETED). Only ICMP ping .96↔.93 is blocked — never use
|
||||
ping as a health check, use HTTP. A reverse-SSH-tunnel approach was
|
||||
built then fully reverted (`e3a905e` → `cb483c0`); direct URL is the
|
||||
sanctioned path.
|
||||
- `docs/ai-handoff-fcp-recount.md`: AI handoff for the FCP-side phase 2.
|
||||
- `ERD.md` (Mermaid ERD) + this changelog (`97507f8`).
|
||||
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
# AI Handoff — FCP → Recounter Clip Repush (Phase 2)
|
||||
|
||||
**Audience:** the next AI agent (or dev) implementing the FCP side.
|
||||
**Status:** Phase 1 (recounter receiver) is DONE and committed. Phase 2 (FCP
|
||||
button + push) is NOT started.
|
||||
**Last updated:** 2026-10-20.
|
||||
**Status:** Phase 1 (recounter receiver) is DONE and committed, E2E-tested
|
||||
from the FCP host. Phase 2 (FCP button + push) is NOT started — that's your job.
|
||||
**Last updated:** 2026-10-20 (post-network-revert; direct connectivity verified).
|
||||
|
||||
---
|
||||
|
||||
## 1. What exists today (verified, tested, live-smoked)
|
||||
|
||||
### feedmill_recounter (port 9050) — receiver, DONE
|
||||
### feedmill_recounter (on `192.168.192.93`, port 9050) — receiver, DONE
|
||||
|
||||
`POST /api/analyze` (app.py, commit `540e1b5`):
|
||||
`POST /api/analyze` (app.py, commits `540e1b5` + review pass `371e959`):
|
||||
|
||||
```bash
|
||||
curl -X POST http://localhost:9050/api/analyze \
|
||||
curl -X POST http://192.168.192.93:9050/api/analyze \
|
||||
-H "X-API-Key: $RECOUNTER_API_KEY" \
|
||||
-F "video=@clip.mp4" \
|
||||
-F "fcp_mode=C" \
|
||||
@@ -30,32 +30,49 @@ curl -X POST http://localhost:9050/api/analyze \
|
||||
| bad/missing key when env set | **401** | `{"error":"unauthorized"}` |
|
||||
| no video / bad ext / unknown fcp_mode / no models | **400** | `{"error":"<msg>"}` (always JSON) |
|
||||
|
||||
- **Auth:** header `X-API-Key` is checked **iff** env `RECOUNTER_API_KEY` is
|
||||
set on the recounter process. Unset = open (current default in
|
||||
`start_dashboard.sh` — set it before exposing beyond LAN).
|
||||
- **Auth:** header `X-API-Key` checked **iff** env `RECOUNTER_API_KEY` is set
|
||||
on the recounter process. **It IS set** on the live .93 instance
|
||||
(`/home/jetson/feedmill_semarang_project/feedmill_recounter/.env`) — the
|
||||
FCP sender MUST send the header with the same value, or expect 401.
|
||||
- **`fcp_mode`** = FCP model-mode letter `A|B|C|D`, mapped server-side via
|
||||
recounter `config.yaml → fcp.mode_models` — a mapping of
|
||||
`{letter: {stem: engine_classes}}` that mirrors FCP `models.modes`
|
||||
`engines[].classes` **exactly** (verified against FCP config 2026-10-20;
|
||||
note FCP B/D use **v4-best in the truck-only role**, NOT the
|
||||
`truck-detector` weights, and mode letters set per-stem class filters
|
||||
e.g. C: `v4-best:[truck,sack]`, `yolo11n…:[box]`). `C` = FCP's current
|
||||
`active_mode`.
|
||||
recounter `config.yaml → fcp.mode_models` — `{letter: {stem:
|
||||
engine_classes}}` mirroring FCP `models.modes engines[].classes`
|
||||
**exactly** (verified against FCP config 2026-10-20; B/D give truck duty
|
||||
to **v4-best**, NOT `truck-detector` weights; per-stem class filters
|
||||
e.g. C: `v4-best:[truck,sack]`, `yolo11n…:[box]`). `C` = FCP's active_mode.
|
||||
- **Field precedence:** if both `fcp_mode` and `model_stems` are sent,
|
||||
**`fcp_mode` wins and `model_stems` is ignored**. Use `model_stems`
|
||||
(multipart, repeatable) + `format_<stem>`/`filter_<stem>` only when
|
||||
`fcp_mode` is absent (manual/custom selection).
|
||||
- **Busy policy:** 409 not a queue. Caller retries. One job at a time =
|
||||
one GPU.
|
||||
**`fcp_mode` wins and `model_stems` is silently ignored**. Use
|
||||
`model_stems` only when `fcp_mode` is absent.
|
||||
- **Busy policy:** 409, no queue, atomic check+enqueue (submit lock —
|
||||
overlapping POSTs cannot both be accepted). Caller retries.
|
||||
- **Results:** poll `status_url` → `{"status":"COMPLETED","results":[
|
||||
{"loading_count","unloading_count","net_count","box_*",
|
||||
"output_path",...}]}`. Download: `GET /download/<job_id>/<filename>`.
|
||||
- Save path is shared with the UI `/upload` (collision-safe filename,
|
||||
auto 720p transcode, fixed-zone resolution) via `_save_and_queue()`.
|
||||
{"loading_count","unloading_count","net_count","box_loading_count",
|
||||
"box_unloading_count","box_net_count","output_path",...}]}`.
|
||||
Download annotated video: `GET /download/<job_id>/<filename>`.
|
||||
- Save path shared with the UI `/upload` (collision-safe filename, auto
|
||||
720p transcode, fixed-zone resolution) via `_save_and_queue()`.
|
||||
|
||||
Tests: `tests/test_api_analyze.py` — 14 cases; full suite **191 passed**.
|
||||
Tests: `tests/test_api_analyze.py` — 18 cases; full suite **195 passed**.
|
||||
|
||||
### FCP (karung_counter_semarang) — sender, NOT STARTED
|
||||
### NETWORK — verified 2026-10-20 (read this, it changes assumptions)
|
||||
|
||||
**Direct FCP→recounter works. Use it.**
|
||||
|
||||
- `192.168.192.96` (FCP host) → `http://192.168.192.93:9050/api/analyze`
|
||||
= **202, job COMPLETED** — live end-to-end smoke done on 2026-10-20
|
||||
(uploaded 2 s test clip from .96, mode C, counts returned).
|
||||
- **ICMP ping .96→.93 is blocked (100% loss) but TCP is NOT.** Earlier
|
||||
analysis wrongly concluded a firewall blocked everything; only ping is
|
||||
dropped. Do not diagnose connectivity with ping — use
|
||||
`curl -m5 http://192.168.192.93:9050/api/models` (expect 200).
|
||||
- motionEye `192.168.192.253:8765` reachable from both .96 and .93 (200).
|
||||
- A reverse-SSH-tunnel approach was built and **fully reverted**
|
||||
(`e3a905e` then `cb483c0`) per operator policy — **do not reintroduce
|
||||
tunnels**; direct URL is the sanctioned path.
|
||||
- `.96` sshd: password auth works (`jetson`); the .93 key we briefly
|
||||
installed was removed in the revert.
|
||||
|
||||
### FCP (karung_counter_semarang on `192.168.192.96`) — sender, NOT STARTED
|
||||
|
||||
Everything needed is already in FCP (researched, file:line verified):
|
||||
|
||||
@@ -75,33 +92,40 @@ Everything needed is already in FCP (researched, file:line verified):
|
||||
`/api/batch-clip/...` (it re-renders).
|
||||
4. **HTTP client:** FCP has **no `requests`** — use stdlib
|
||||
`urllib.request` (repo idiom; `src/clip.py` uses it).
|
||||
5. **Ports:** operator 5000, office 5721, external proxy 80/443 →
|
||||
`api.` host or `/api/` → 5721. New endpoints must be gated with
|
||||
`is_office_request()` like the four existing clip routes.
|
||||
5. **Ports:** operator 5000, office 5721 (both live on .96), external
|
||||
proxy 80/443 → `api.` host or `/api/` → 5721. New endpoints must be
|
||||
gated with `is_office_request()` like the four existing clip routes.
|
||||
6. **Templates gotcha:** `templates/history.html` `renderClipButtons()`
|
||||
(~L548-549) rewrites `innerHTML` of **any**
|
||||
`#batchesTableBody button[data-batch]`. A new button MUST use a
|
||||
different data attribute (e.g. `data-recount`) and its own
|
||||
`apply*State` fn — do not reuse `data-batch`.
|
||||
7. **Batch mode switch note:** `GET /api/model-modes` is `editable:false`
|
||||
on operator port, `editable:true` on office port (checked 2026-10-20) —
|
||||
consistent with office-only gating for the new endpoint.
|
||||
|
||||
## 2. Environment / URLs (given by operator)
|
||||
## 2. Environment / URLs
|
||||
|
||||
```
|
||||
MOTIONEYE_URL=http://192.168.192.253:8765
|
||||
MOTIONEYE_CAMERA_ID=2
|
||||
```
|
||||
|
||||
Suggested new FCP env (`.env`, read like the other motioneye vars):
|
||||
New FCP env (`.env`, read like the other motioneye vars):
|
||||
|
||||
```
|
||||
RECOUNTER_URL=http://localhost:9050 # http://192.168.192.96:9050 from other hosts
|
||||
RECOUNTER_API_KEY= # must equal recounter's RECOUNTER_API_KEY
|
||||
RECOUNTER_URL=http://192.168.192.93:9050
|
||||
RECOUNTER_API_KEY=<same 43-char value as recounter's .env RECOUNTER_API_KEY>
|
||||
```
|
||||
|
||||
Jetson IP in `external_proxy.py` is `192.168.192.96`; recounter web UI is
|
||||
`http://<host>:9050`.
|
||||
Get the key value: `cat /home/jetson/feedmill_semarang_project/feedmill_recounter/.env`
|
||||
(on .93; never commit it — FCP `.env` is gitignored).
|
||||
|
||||
## 3. Design for Phase 2 (recommended, ~sizable but follows existing patterns)
|
||||
Hosts: FCP = `192.168.192.96` (`jetson-km9-semarang`, matches `JETSEN_IP`
|
||||
in `external_proxy.py`); recounter = `192.168.192.93`
|
||||
(`zenai-jetson-kantor`).
|
||||
|
||||
## 3. Design for Phase 2 (recommended, follows existing FCP patterns)
|
||||
|
||||
**Endpoint:** `POST /api/batch-recount/<date>/<batch_number>` (office-only)
|
||||
|
||||
@@ -109,29 +133,32 @@ Flow inside handler (mirror the clip worker pattern):
|
||||
1. Look up batch in DB for its window + `model_mode` (fallback:
|
||||
`GET /api/model-modes` active letter).
|
||||
2. Ensure clip ready: check `_CLIP_JOBS` status; if none/error, chain the
|
||||
existing clip POST first (reuse `_render_clip_job` logic or re-POST
|
||||
internally) — **or** simplest v1: require clip `ready`, else 409 with
|
||||
`"clip dulu"` message.
|
||||
3. Read clip tmp file → multipart POST to `RECOUNTER_URL/api/analyze`
|
||||
via `urllib` (encode multipart manually or read
|
||||
`src/clip.py`/`predict.py` for an existing encoder — if none, a small
|
||||
`MultipartEncoder`-style helper with stdlib `uuid` boundary is ~30
|
||||
lines).
|
||||
4. Send `fcp_mode=<letter>`, header `X-API-Key` if `RECOUNTER_API_KEY`
|
||||
env set.
|
||||
existing clip POST first — **or** simplest v1: require clip `ready`,
|
||||
else 409 with `"clip dulu"` message.
|
||||
3. Read clip tmp file → multipart POST to
|
||||
`RECOUNTER_URL/api/analyze` via stdlib `urllib.request` (encode
|
||||
multipart manually — ~30-line helper with `uuid` boundary; no existing
|
||||
encoder in repo).
|
||||
4. Send `fcp_mode=<letter>` + header `X-API-Key` when
|
||||
`RECOUNTER_API_KEY` env set.
|
||||
5. Store in a new `_RECOUNT_JOBS` registry (copy `_CLIP_JOBS` structure):
|
||||
`{status: running|ready|error, job_id, recounter_url, error, elapsed}`.
|
||||
`{status: running|ready|error, job_id, error, elapsed}`.
|
||||
6. `GET /api/batch-recount/<date>/<n>/status` polls recounter
|
||||
`/api/jobs/<job_id>` server-side (avoids CORS) and returns combined
|
||||
`{recounter_status, counts...}`.
|
||||
`/api/jobs/<job_id>` server-side (avoids browser CORS) and returns
|
||||
combined `{recounter_status, counts...}`.
|
||||
|
||||
**UI:** `templates/history.html` — sibling button in the same `<td>` as
|
||||
Klip, `data-recount` attr, own dispatcher `onRecountClick()`, own state
|
||||
map, label flow: `Hitung ulang` → `Mengirim…` / `Memproses… N%` →
|
||||
`Selesai — lihat` (link to `RECOUNTER_URL/status/job-...`) / `Gagal`.
|
||||
|
||||
**409 handling:** show a toast/`alert("Sedang ada proses — coba lagi")`
|
||||
and retry poll after a few seconds; do not auto-loop >3 retries.
|
||||
**Status-code handling (all live-verified against the real receiver):**
|
||||
- 409 → `"Sedang ada proses — coba lagi"`; retry poll a few seconds; do
|
||||
not auto-loop >3 retries.
|
||||
- 401 → `"API key salah"` (check FCP `.env`).
|
||||
- connection error/timeout → `"Recounter tidak terhubung"` (recounter
|
||||
process down on .93 — ping is blocked, use GET /api/models to test).
|
||||
- 400 → show `{"error"}` text verbatim.
|
||||
|
||||
**Safety rules:**
|
||||
- Never read/write recounter paths from FCP (or vice versa) — HTTP only.
|
||||
@@ -140,23 +167,25 @@ and retry poll after a few seconds; do not auto-loop >3 retries.
|
||||
|
||||
## 4. Verification checklist for Phase 2
|
||||
|
||||
- [ ] FCP: POST recount returns 202/202-analogue without touching operator port
|
||||
- [ ] FCP: `curl $RECOUNTER_URL/api/models` from .96 → 200
|
||||
- [ ] FCP: POST recount returns 202-analogue without touching operator port
|
||||
- [ ] Recounter job created and reaches COMPLETED with counts for a real clip
|
||||
- [ ] 401 surfaces as friendly "API key salah" error, not traceback
|
||||
- [ ] 409 surfaces as retry message, button not stuck busy
|
||||
- [ ] Clip missing/expired → clear error, button returns to idle
|
||||
- [ ] `renderClipButtons()` does NOT clobber the new button (grep innerHTML renders)
|
||||
- [ ] Existing clip button still works (regression)
|
||||
- [ ] FCP: `pytest` green; recounter: `python -m pytest tests/ -q` → 191 pass
|
||||
- [ ] FCP: `pytest` green; recounter: `python -m pytest tests/ -q` → 195 pass
|
||||
|
||||
## 5. Repo facts
|
||||
|
||||
| Fact | Value |
|
||||
|---|---|
|
||||
| FCP root | `/home/jetson/feedmill_semarang_project/karung_counter_semarang` |
|
||||
| Recounter root | `/home/jetson/feedmill_semarang_project/feedmill_recounter` |
|
||||
| Recounter branch | `main`; phase 1 commits: `540e1b5` (endpoint), `97507f8` (ERD/CHANGELOG) |
|
||||
| Recounter suite | `python -m pytest tests/ -q` → 191 passed |
|
||||
| FCP root (.96) | `/home/jetson/feedmill_semarang_project/karung_counter_semarang` (prod copy `/opt/jetson-counter`) |
|
||||
| Recounter root (.93) | `/home/jetson/feedmill_semarang_project/feedmill_recounter` |
|
||||
| Recounter branch | `main`; phase 1: `540e1b5` (endpoint), `371e959` (review pass: atomic busy, exact mode filters) |
|
||||
| Network commits (reverted, historical) | `e3a905e` tunnel built → `cb483c0` revert |
|
||||
| Recounter suite | `python -m pytest tests/ -q` → 195 passed |
|
||||
| Recounter mode map | `config.yaml → fcp.mode_models` (A/B/C/D) |
|
||||
| FCP clip endpoints | `counter_dashboard.py:1736/1760/1854/1881` |
|
||||
| FCP mode endpoint | `GET /api/model-modes` (fresh-read active_mode) |
|
||||
@@ -171,9 +200,9 @@ truck duty to v4-best, engine `classes` act as the per-stem filter).
|
||||
|
||||
- Recounter has **no queue** — 409 only. If FCP needs reliable retry,
|
||||
Phase 2 should implement backoff, not ask for a recounter queue.
|
||||
- `RECOUNTER_API_KEY` unset by default — recommend operator sets
|
||||
identical value in FCP `.env` and recounter `.env` before LAN exposure.
|
||||
- Recounter config `fcp.mode_models` must be kept in sync manually if FCP
|
||||
adds mode E/F with new engines (no cross-repo sync by design).
|
||||
- `tests/test_api_analyze.py` stubs `_save_and_queue`; real save path
|
||||
smoke-tested manually with a 2 s generated mp4 (202 → COMPLETED).
|
||||
smoke-tested manually (2 s generated mp4 from .96 → 202 → COMPLETED).
|
||||
- ICMP ping .96↔.93 is blocked both ways — never use ping as a health
|
||||
check between the two hosts; use HTTP.
|
||||
Reference in new issue
Block a user