Files
parking_solution/wiki/decisions/forgiven-exit.md
T
julian a761398301
Build & push images / images (push) Successful in 3m23s
feat(exit): forgiven exit — open the exit barrier with no payment (barrier:create)
The owner (or any role the owner grants barrier:create) lets a car out for free.
Exit side only. Every use is signed, attributed, photographed and on the operator's
Z-report; the shift's cash/card/drawer are untouched by construction.

- shared: resource 'barrier' + permission 'barrier:create'; reason codes
  exit.forgiven / exit.forgiven.noSession; LedgerPayload.forgoneMinor.
- pay-station: forgive() signs a $0 payment carrying the quoted fee as forgoneMinor
  (no tender), refuses a ticket with module charge lines (a wash is not forgiven).
- exit-flow: reopenBarrier(..., { forgiven }) bypasses the walk-back check and stamps
  the forgiven reason on the anomaly + vehicle_exit; forgiveExitNoSession() for a car
  with no ticket (anomaly under forgiven:<id> + exit snapshot + pulse). Relay driving
  shared in #pulseExit.
- route POST /api/barrier/forgive { identity?, note? }: barrier:create + open shift;
  the reason is optional (an empty note is signed as '(no reason given)').
- shift-service: forgoneTotalMinor + forgoneCount on the report/summary/signed
  shift_z_report (only when > 0), print line 'Dalje të falura (N)'.
- web: 'Forgive & open' in the pay/exit modal for an open transient that owes money;
  'Forgive & open exit' on the booth header for the no-ticket case; forgone line on
  the X-report, close confirm and history; en/sq. Prints nothing.
- tests: exit-flow, pay-station, shift-service, HTTP route (403 without the
  permission, 409 no shift, empty note accepted, ledger sequence, report figures).
- wiki: decisions/forgiven-exit.md (decision + as-built), booth-exit-flow, shift,
  index, log.
2026-10-09 08:14:36 +02:00

104 lines
6.7 KiB
Markdown

---
type: decision
tags: [parking, decisions, exit, barrier, threat-model, shift, z-report, permissions]
sources: []
updated: 2026-10-08
status: built 2026-10-08
---
# Forgiven exit — the owner opens the EXIT barrier with no payment
> **Built 2026-10-08** (same day as decided). As-built notes at the end of this page; the
> decisions below are what shipped.
**The ask (user, 2026-10-08).** The owner/admin sometimes needs to let a car out regardless:
a transient that took a ticket but will not be charged, or a car with no session at all (it
came in while the barriers were up). The open must produce **no money** and must be **flagged**
in the live feed. First floated for both directions; **narrowed the same day to the EXIT
barrier only** — the entry keeps its existing paths ([[operator-issued-entry]] when the button
is broken, barriers physically up otherwise).
## Why it is safe to give the operator this at all
This is the exact move the [[threat-model]] worries about (pocket the fee, "lose" the ticket,
let the car out). As with [[operator-issued-entry]], the defence is not to withhold the
capability but to make every use **signed, attributed, photographed and impossible to hide**:
it lands on a named operator's shift, with the fee it forgave, where the owner reads it.
## Decisions
1. **Exit only.** Reuses the human-intervention re-open path in `exit-flow.ts`
(`reopenBarrier`: anomaly signed FIRST, then the human-intervention `vehicle_exit`, exit
snapshot, `pulseOpen`). Today that path refuses an unpaid or grace-expired transient; the
feature is a **second authorization branch** on it, behind a dedicated permission.
2. **Accounting: a signed ZERO-amount payment that carries the forgone fee.** The Z-report
([[shift]]) sums `amountMinor` by tender, so a zero payment adds nothing to cash, card or the
drawer — the shift total is untouched by construction. The fee the car owed is recorded in
its **own field** (`forgoneMinor`, with a reason code), reported as its **own line**
("forgone exits: N, amount X"), and is NOT the merchant-validation `discountMinor` — the
owner must be able to tell "the bar validated it" from "the operator let it out".
Signing the payment also **closes the ticket**, so it cannot be reused ([[plate-reconciliation]]
ticket-swap).
3. **No session (car has no ticket, e.g. came in with the barriers up):** signed anomaly with
the exit snapshot and the plate read, then the pulse. Nothing to forgive, nothing to close.
4. **Permission:** a new one, **admin only by default**; the owner decides whether operators get
it. Requires an **open shift** (same `requireShift` as the pay routes) so every use is on
someone's report.
5. **Reason text is OPTIONAL** (user, 2026-10-09 — reversed from "mandatory" the day before:
"We don't need to force the user to write a reason"). The accountability is the
signature, the operator name, the snapshot and the Z-report line; an empty note is signed
as "(no reason given)" so the English sentence stays readable.
6. **Print nothing.** No receipt, no slip — there is no payment to receipt (user, 2026-10-08).
7. **Visibility:** warn-level log line, anomaly in the live feed with the snapshot, the Z-report
line. **No cap, no blocking** — blocking the owner at the gate recreates the "lot stuck"
problem; the defence is reporting.
8. **Safety unchanged:** `pulseOpen` only, never a timed close ([[fail-state-safety]]).
## Not decided / out of scope
- Entry-side free open: **rejected** for now (the entry has its own paths).
- Whether a forgiven exit should also void an attached car-wash charge line: open; today the
zero payment would carry no charge lines at all.
## Build sketch (when asked)
`exit-flow.reopenBarrier(identity, operator, { forgive: { reason } })` → quote the fee as the
pay flow would (PayStation quote), sign `payment { amountMinor: 0, forgoneMinor, reason }`,
then the existing re-open body. Route `POST /api/barrier/forgive` with the new permission +
`requireShift`. Z-report: `forgoneTotalMinor` + `forgoneCount` (old reports → 0), one print
line. Web: a guarded button in the pay/exit modal, reason field optional. Reason codes:
`exit.forgiven`, `exit.forgiven.noSession`. Tests on the no-money invariant (cash/card/drawer
unchanged) and on the ticket being closed.
## As built (2026-10-08)
- **Permission `barrier:create`** (new resource `barrier` in the code-defined grid,
`packages/shared`). Admin has it by the all-permissions invariant; the owner grants it to any
role from Setup → Roles — "the owner can give permission to other operators" (user).
- **`PayStation.forgive(identity, { operator, note })`** — quotes the fee as the pay flow
would, signs `payment { amountMinor: 0, forgoneMinor: <quote>, operator, reasonCode:
"exit.forgiven", reason: "forgiven exit by X — fee of N CUR waived: <note>" }` with **no
tender** (nothing was tendered), marks the projection paid. Refuses (409) when the quote
carries module charge lines (a wash on the ticket): parking is forgiven, a wash is not.
- **`ExitFlow.reopenBarrier(id, operator, { forgiven })`** — the existing human-intervention
re-open with the walk-back check bypassed for a forgiven call (a 0-minute grace tariff must
not refuse it); the anomaly and the `vehicle_exit` carry `exit.forgiven` + `forgiven: true`
+ `forgoneMinor`. **`ExitFlow.forgiveExitNoSession(operator, note)`** — anomaly under a fresh
`forgiven:<uuid>` identity (so its exit snapshot shows in the feed) + pulse; no payment, no
exit event. Relay driving shared in `#pulseExit` (signed first; a failed pulse is
`ok:true, opened:false` + "open by hand").
- **Route `POST /api/barrier/forgive { identity?, note? }`** — `barrier:create` + the open-shift
gate (`409 no_shift`); the note is optional; no identity = the no-session path.
- **Z-report**: `forgoneTotalMinor` + `forgoneCount` summed from `forgoneMinor` (never into
cash/card; `discountTotalMinor` untouched), on the signed `shift_z_report` only when > 0, one
print line `Dalje të falura (N): X`, shown in the X-report, the close confirm and history.
- **Web**: in the pay/exit modal a red ghost "Forgive & open" for an OPEN transient that owes
money (unpaid or overstay) → reason box → "Confirm — open exit, no payment"; on the booth
header a "Forgive & open exit" next to the exit lane light for the no-ticket case
(`window.prompt` for the reason — Cancel aborts, empty proceeds). Both only render with
`barrier:create` + own open shift.
Live-feed reason texts in en/sq. **Nothing is printed.**
- Tests: exit-flow (ticketed + no-session), pay-station (`forgive`), shift-service (totals
untouched, own line, history), routes (403 without the permission, 409 no shift, 400 no
note accepted, ledger sequence entry→payment→anomaly→exit, report figures).