diff --git a/scripts/__pycache__/dingtian_qr.cpython-312.pyc b/scripts/__pycache__/dingtian_qr.cpython-312.pyc deleted file mode 100644 index b8b91f6..0000000 Binary files a/scripts/__pycache__/dingtian_qr.cpython-312.pyc and /dev/null differ diff --git a/wiki/concepts/barrier-not-a-door.md b/wiki/concepts/barrier-not-a-door.md index bcf7765..7501188 100644 --- a/wiki/concepts/barrier-not-a-door.md +++ b/wiki/concepts/barrier-not-a-door.md @@ -18,3 +18,8 @@ timed auto-close can **drop a boom on a vehicle or person**. (See [[parking-syst - Holds **regardless of which relay device** is used — [[uhppote-controller]] or [[esp32-custom-controller]]. The ESP32 design restates it: "the ESP32 only signals intent" (see [[fail-state-safety]]). +- **Proposed revision, not repeal (2026-10-24):** [[passage-confirmation]] asks to *express* a + close after a vision-verified abandonment (driver reversed out, boom left up because the + operator's sensor was never tripped). Still never timed, never blind: only with a fresh verdict, + an empty lane in the tracker, and after bench tests that the operator's loop/photocell override + the command. Until those tests pass on park-lab the rule stands unchanged. diff --git a/wiki/concepts/lane-presence-and-anpr-entry.md b/wiki/concepts/lane-presence-and-anpr-entry.md index 517f972..6079980 100644 --- a/wiki/concepts/lane-presence-and-anpr-entry.md +++ b/wiki/concepts/lane-presence-and-anpr-entry.md @@ -208,3 +208,7 @@ the actual booth PC to test on. - **Gate the entry ticket button on lane-busy** (don't print when no car) — deferred. The lane-busy signal supports it, but it gates a PHYSICAL action so it must FAIL-OPEN (allow when presence is unknown). Parked pending the user's real goal (anti-spam print vs one-ticket-per-car). +- **Successor design (2026-10-24):** [[passage-confirmation]] replaces the still-pull loop with a + persistent RTSP sub-stream watcher, adds a tracker and a drawn A→B segment, and turns lane + presence into a positive signal (free when the tracked car crossed the line, busy while it sits + between line and boom). The ANPR bridge and the crossing tracker share the decoded frames. diff --git a/wiki/concepts/park-2-event-loop-stall.md b/wiki/concepts/park-2-event-loop-stall.md index f2f9a59..f5e5d7a 100644 --- a/wiki/concepts/park-2-event-loop-stall.md +++ b/wiki/concepts/park-2-event-loop-stall.md @@ -80,3 +80,12 @@ plate scan 78 ms, both now index-assisted), and stops growing with open-ticket c Related: [[booth-exit-flow]] (active list semantics), [[append-only-event-chain]], [[device-events]], [[dingtian-relay]], [[appliance-provisioning]] (park-2 host history). + +## Deployed and measured (2026-10-24, stage-73ada89 on park-lab then park-2) + +Migration 0032 applied at container start (both sites); all six indexes present and chosen by the +planner. On park-2, same hour, same traffic: `GET /api/sessions/active` **~2.0–2.6 s → 290–390 ms**; +no other request above 300 ms; first subscription relay pulse **46 ms** (the old container had +logged 2.2 s pulses minutes earlier). The remaining ~300 ms is the whole-ledger fold + the plate +telemetry scan — index-assisted, growing slowly with total history, no longer with open tickets. +Next step for a flat handler: cache the fold keyed on the ledger head `index`. diff --git a/wiki/concepts/passage-confirmation.md b/wiki/concepts/passage-confirmation.md new file mode 100644 index 0000000..6c17df5 --- /dev/null +++ b/wiki/concepts/passage-confirmation.md @@ -0,0 +1,116 @@ +--- +type: concept +tags: [parking, vision, barrier, lane, ledger, safety, design] +sources: [] +updated: 2026-10-24 +status: open +--- + +# Passage confirmation — did the car actually cross? (design, 2026-10-24) + +**Problem (user, 2026-10-24).** A motion push opens the barrier and signs the entry/exit. If the +driver changes their mind and reverses out, the ledger holds a false entry, and — because the +barrier operator at the sites closes **only when its sensor/radar is tripped by a passage** — the +boom stays up until the next car trips it. That next car enters with no ticket, no read, no ledger +row. So an abandoned entry is both a wrong row and a free pass. Related: the FIFO stale-occurrence +problem seen on AB694XU the same day (an exit closes the oldest open occurrence; one double read +leaves a subscriber permanently one stay behind). + +**Constraint (user).** The cameras are the cheap Hikvision DS-2CD1043G2-LIU: motion push with a +vehicle target, a sub-stream, and no line-crossing / smart events. The booth PC does the thinking. +Cameras are sensors; compute is ours. The Dahua bench unit has tripwire (`CrossLineDetection`) but +that is not the fleet camera. + +## Design + +1. **Frames: the RTSP sub-stream, not ISAPI stills.** Keep one RTSP session open per camera + permanently (avoids the keyframe start-up gap of 1–2 s; set the sub-stream I-frame interval to + ≤ 1 s). Decode in the vision service (OpenCV 4.13 with FFmpeg is already in the container; no + `ffmpeg` binary needed). The still-pull loop in `anpr-entry.ts` is replaced by this — it also + removes the single-threaded picture-endpoint collisions (503s). + *Latency (user asked 2026-10-24):* RTSP itself adds nothing meaningful; the delay is the + camera's encoder (~100–300 ms) plus whatever the decoder buffers. Open the stream with a + minimal buffer (`CAP_PROP_BUFFERSIZE 1`, TCP transport, drop to the newest frame), and the + watcher sees a frame well under half a second after the event. The 1–2 s start-up gap is a + keyframe wait, which is why the session stays open. To be measured on park-lab against the + motion-push timestamp once a camera is on the bench. +2. **Trigger and window.** Nothing runs while the lane is empty. A motion push starts a *watch* on + that camera; it holds while pushes keep arriving (1–3 s apart while a car moves — see + [[lane-presence-and-anpr-entry]]) and ends a few seconds after they stop, or at a hard cap. +3. **Detection + tracking.** The existing YOLOX vehicle detector gives a box per car; a small + in-house tracker matches boxes between frames by overlap and follows each track's + **bottom-centre point** (ground contact; stable under perspective). No tracker library. +4. **The segment.** Drawn once per camera in Setup over a live frame; stored as two normalised + points + which side is A, in the same normalised frame the plate/vehicle boxes already use. + Crossing = sign change of the cross product of the tracked point against the segment. A→B on + the entry camera is a passage; the exit camera has its own line. A→B→A inside the window is a + reversal (not a passage). The verdict carries the track's plate if ANPR read one on it. +5. **One watcher, two consumers.** The same decoded frames feed the ANPR bridge (subscriber + auto-open) and the crossing tracker (confirmation). +6. **Lane state becomes positive.** Busy while any track is between the line and the boom; free + when the last track crossed or left the frame; the 30 s TTL stays only as a fallback when the + stream is down. `vehicle_passed` ⇒ lane free *unless another track is present* (tailgating). + This is the software form of the pass-through sensor [[entry-double-press]] asked for. + +### Ledger semantics (append-only, unchanged open path) + +- `vehicle_entry` / `vehicle_exit` remain **intent**: the barrier was commanded open. The open is + never delayed by confirmation. +- `vehicle_passed` (new, signed): the crossing was seen, with how (vision track) and the plate. +- `entry.abandoned` / `exit.abandoned` (new, signed): window ended with no crossing. Closes the + occurrence; a printed ticket is **invalidated** so the paper cannot be handed to the next car. +- *unverified*: vision/stream unavailable — recorded as such; the stay counts (benefit of doubt). + Occupancy and the active list count passed + unverified; abandoned are listed as what they are. + A subscriber's stay only exists once the car is seen to cross — which also kills the stale + FIFO occurrence at its root. + +### Closing the boom after an abandonment — evidence-driven, never timed + +[[barrier-not-a-door]] stays: no timed close. A close may be **expressed** (a pulse on a spare +Dingtian channel into the operator's *close* input) only when **all** hold: an abandoned verdict; +the tracker reports nothing between the line and the boom and nothing approaching, for a few +seconds; no new open since; the watch is alive (stream up, verdict fresh); and the close is itself +a signed event with the last frame attached. Vision down ⇒ no close, ever (today's behaviour). +The operator's safety devices (loop / photocell) must be verified to override a close command +on the real unit before this ships. Requires a revision (not repeal) of the standing decision, +with the test results attached. + +## Test plan — on park-lab (user, 2026-10-24: "we will test it on park-lab") + +1. Confirm the operator's close input; wire a spare relay to it. +2. Close with a car on the safety loop → boom must not move / must reverse. +3. Close with the photocell beam broken by a person → same. +4. Reversal: open, back out, window expires → close pulses, boom comes down. +5. Tailgate: second car approaching while the first backs out → the tracker holds the close. +6. Vision service stopped: reversal again → boom stays up, event logged unverified. + +## Measured on park-lab (2026-10-24, i5-9500, vision container, CPU only) + +YOLOX-S ONNX, input fixed at 640 by the exported graph (smaller inputs need a re-export): + +| intra-op threads | ms / frame (p50) | ≈ fps on that budget | +| --- | --- | --- | +| 2 (service default) | 132 | 7.5 | +| 4 | 79 | 12.5 | +| 6 | 66–70 | 14 | + +Decode of a 704×576 sub-stream frame is < 1 ms (MPEG-4 part 2 proxy; H.264/H.265 will be a few +ms) — negligible next to inference. So one lane at 5–6 fps costs ~0.7–0.8 of two cores during a +watch and nothing between watches; two lanes at once need 4 threads or detection on alternate +frames with the tracker interpolating. Cheaper still: re-export YOLOX at 416 (~2.4× fewer FLOPs) +or switch to YOLOX-Tiny/Nano for the tracker (the plate stage keeps its own detector). + +**Still needed to measure the stream path:** a camera on the bench. The lab Dahua (10.0.10.11) was +off on 2026-10-24; the office Hikvisions on the same net (10.0.10.122/.125/.126/.128) need +credentials. Nothing of park-lab's device registry has a camera yet (only the relay emulator). + +## Open questions + +- Re-export YOLOX at 416 vs YOLOX-Tiny for the tracker — accuracy on far cars at the line? +- Window cap and "lane clear" dwell before a close (start: cap 60 s, dwell 3 s). +- Does the DS-2CD1043G2-LIU keep pushing VMD for a car *reversing*? (It should — motion is motion.) +- Stream-to-event latency and frame drop rate on the booth PC (measure, don't assume). +- Which barrier operator model is at the sites, and does park-lab have one for steps 1–6? + +Related: [[lane-presence-and-anpr-entry]], [[barrier-not-a-door]], [[entry-double-press]], +[[append-only-event-chain]], [[opencv-anpr-service]], [[park-2-event-loop-stall]]. diff --git a/wiki/decisions/open-questions.md b/wiki/decisions/open-questions.md index cdca148..e4079dd 100644 --- a/wiki/decisions/open-questions.md +++ b/wiki/decisions/open-questions.md @@ -179,6 +179,15 @@ procurement. (See [[parking-system-architecture]] §10.) [[device-discovery-roadmap]]. Settles when cameras and printers scan from the wizard and the relay's search reply has been captured on the bench. +20. **Passage confirmation and the evidence-driven close.** _(Raised by the user, 2026-10-24.)_ + A motion push opens the barrier and signs the entry; a driver who reverses out leaves a false + ledger row and, because the operator closes only on its own sensor, an open boom for the next + car. Design in [[passage-confirmation]]: booth-PC tracker on the RTSP sub-stream, a drawn + segment, signed `vehicle_passed` / `*.abandoned`, and a close expressed only on fresh vision + evidence. Settles when the park-lab tests (loop/photocell override, reversal, tailgate, vision + down) pass and [[barrier-not-a-door]] is revised with the results attached. Needs a camera and + a barrier operator on park-lab first. + ## Cloud takeover mode vs. the signed ledger (2026-10-22, parked) If the cloud commands the barrier while the booth PC is dead ([[relay-proxy-firmware]]), entry/exit diff --git a/wiki/index.md b/wiki/index.md index 7f683da..25bf391 100644 --- a/wiki/index.md +++ b/wiki/index.md @@ -102,6 +102,7 @@ Counts: 4 sources · 19 entities · 47 concepts · 9 decision records. - [[tariff-industry-survey]] — 2026-07 web survey of industry tariff structures: coverage map vs our engine; gaps = early bird (pick-table-by-entry-time) + merchant validations; per-minute & dynamic pricing ruled out. - [[booth-exit-flow]] — manned booth: pay → voucher (self-exit later) or immediate exit; active sessions; audited barrier re-open. - [[park-2-event-loop-stall]] — INCIDENT 2026-10-24: `/api/sessions/active` ran ~2 s synchronously (per-row unindexed ledger scans × 664 open unpaid tickets), froze the event loop, and made healthy Dingtian pulses report "timeout" (timers run before socket I/O) → signed entries with no snapshot/session row. Fix: fold-once pricing, hot-path indexes (0032), deferred UDP timeout, evidence before pulse. Rule: bounded request cost whatever the operator data. +- [[passage-confirmation]] — DESIGN 2026-10-24 (open): confirm a car actually crossed after the open, on the booth PC (cheap cameras have no line-crossing): sub-stream watcher + YOLOX tracker + a drawn segment → signed `vehicle_passed` / `entry.abandoned`; lane free on passage; evidence-driven (never timed) close on a spare relay after an abandonment; park-lab test plan; measured 66–132 ms/frame. - [[operator-issued-entry]] — operator mints an entry ticket when the physical button is broken; presence-gated (radar AND camera, both sides), flagged (source=manual + operatorInitiated + anomaly), capacity-override allowed; needs `session:create` (2026-07-01). - [[plate-reconciliation]] — ANPR plate-as-invariant catches the ticket-swap fraud (paid car let out on a fresh $0 ticket, original lingers "inside"); exact/high-conf match vs open sessions; booth = flag + operator override, reader = log-only fail-open (2026-07-01). - [[shift]] — manned-only accountability period; explicit Start/End; End → signed + printed Z-report; drawer float carries across shifts. Drawer cash movements (operator records, admin reviews via signed cash_review — a flag, not a reversal) live at the /drawer route (2026-07-01). diff --git a/wiki/log.md b/wiki/log.md index 98ea8f5..8a29291 100644 --- a/wiki/log.md +++ b/wiki/log.md @@ -3616,3 +3616,18 @@ unindexed ledger scans), 2234 calls/day; Node runs expired timers before queued and [[booth-exit-flow]]. Code fix on stage (uncommitted): fold-once pricing in `pay-station.ts`, migration 0032 indexes, `setImmediate` timeout in `access-dingtian.ts`, snapshot/cache before pulse in `subscription-flow.ts`. 390/390 server tests, 6/6 Dingtian tests pass. + +## [2026-10-24] deploy | stage-73ada89 to park-lab and park-2 (bounded active-sessions cost) + +Commits 6eb6536 (wiki), 73ada89 (fix), 44e095c / f5f8865 (TAG bumps). Verified in-container on +both: migration 0032 applied, indexes used. park-2: `/api/sessions/active` 2.0–2.6 s → 0.29–0.39 s, +relay pulse 46 ms, no requests ≥300 ms. Details appended to [[park-2-event-loop-stall]]. + +## [2026-10-24] query | Passage confirmation (A→B crossing) on the booth PC — design + park-lab measurement + +User: cheap DS-2CD1043G2-LIU has no line-crossing; the barrier closes only when its sensor is +tripped, so an abandoned entry leaves the boom up for the next car. Filed [[passage-confirmation]]: +sub-stream watcher, tracker over the existing YOLOX boxes, drawn segment, three signed outcomes, +lane-free on passage, evidence-driven close (standing decision to be revised after park-lab tests). +Measured in park-lab's vision container: YOLOX-S@640 = 132/79/66 ms per frame at 2/4/6 threads; +decode negligible. Stream test blocked: lab Dahua off, office Hikvisions need credentials.