diff --git a/wiki/concepts/backup-recovery.md b/wiki/concepts/backup-recovery.md index a027f0d..4e2e4ab 100644 --- a/wiki/concepts/backup-recovery.md +++ b/wiki/concepts/backup-recovery.md @@ -2,7 +2,7 @@ type: concept tags: [parking, durability, backup, recovery, security, crypto] sources: [] -updated: 2026-08-30 +updated: 2026-11-20 --- # Backup & Disaster Recovery @@ -133,6 +133,12 @@ operator.** The procedure: ## Retention at the destination +> **park-2, 2026-11-20 ([[park-2-disk-growth]]).** The code default (keep-last 7, keep-daily 30) with +> uncompressed full copies of a 6.6 GB DB is ~127 GB and grows ~4.6–6.2 GB a day, because each new +> copy is 30 days of DB growth bigger than the one it replaces. park-2's target is `/data/backup`, on +> the same disk as the DB, which gives no protection against losing the disk. The plaintext +> intermediate goes to `os.tmpdir()`, also the same disk (~6.8 GB for the length of the run). + **Keep last N + thinned dailies** (e.g. last 7 daily / last 4 weekly) — bounded disk use, and it survives the "a bad/partial run clobbered the only good copy" failure. (A single rolling overwrite-latest file was rejected for exactly that reason.) diff --git a/wiki/concepts/entry-exit-points.md b/wiki/concepts/entry-exit-points.md index 0475e86..023f19b 100644 --- a/wiki/concepts/entry-exit-points.md +++ b/wiki/concepts/entry-exit-points.md @@ -2,7 +2,7 @@ type: concept tags: [parking, architecture, devices, setup] sources: [] -updated: 2026-06-30 +updated: 2026-11-20 --- # Entry / Exit Points (pool-of-spaces model) @@ -141,6 +141,13 @@ doesn't move disk-used% until the VACUUM, the loop is driven by **estimated free (`SUM(length(bytes))` of deleted rows), not a live disk re-read. On a roomy booth disk this is a near-permanent no-op. (Replaced the first cut's age/row-cap model the same day.) +> **Contradiction found on park-2 (2026-11-20), see [[park-2-disk-growth]].** It is not a no-op +> there. Nightly full backups on the same disk push it past 70%, and the valve then deletes all but +> the newest 500 snapshots (its 10%-of-disk target is bigger than all snapshots together), every +> day. It runs synchronously on the main thread over a table with no `captured_at` index, so a +> server freeze is likely. Two-thirds of snapshots are Car Wash `pass:` samples that nothing else +> deletes. + ### Refused entry/exit ALSO snapshots (2026-06-19) A snapshot is evidence of **who was at the barrier** — which matters *most* when the barrier is **refused** (a turned-away car is a fraud/dispute signal: "lot full" denial, an unpaid exit attempt, diff --git a/wiki/concepts/park-2-disk-growth.md b/wiki/concepts/park-2-disk-growth.md new file mode 100644 index 0000000..f6530ee --- /dev/null +++ b/wiki/concepts/park-2-disk-growth.md @@ -0,0 +1,172 @@ +--- +type: concept +tags: [parking, incident, disk, backup, snapshots, sqlite, park-2] +sources: [] +updated: 2026-11-20 +--- + +# park-2 disk growth: backups fill the disk, and the snapshot valve fires first (2026-11-20) + +An incident analysis, all measured read-only on park-2 (`stage-73ada89`, container up since +2026-11-09 14:16 UTC) on 2026-11-19 and 2026-11-20. **Status: open, deferred (user, 2026-11-20).** +The immediate hazard was removed by hand; the code fixes wait until the feature work on `stage` is +in a deployable state. The next deadline is **~2026-12-05**. + +## State after the manual cleanup (2026-11-20) + +- The user deleted the old backup files on the host. Six remain (2026-11-14 to 2026-11-19, 35 GB). + `df`: 231 GB, 63 GB used, **29%**. The valve is a no-op and a container restart is safe. +- **Retention is unchanged** (code default, keep-last 7 + keep-daily 30). The user has no app login + on park-2: the admin account belongs to the site's admin. The folder regrows ~6.5 GB a night and + the disk reaches 70% again around **2026-12-05**. Until a fix ships: delete old files by hand + again, or ask the park-2 admin to set 7/7 in Setup → Backup. +- Not done, by decision: a support user written into the DB from the filesystem. It would be an + account the site admin did not create. A support login, if wanted, is created by the admin in + the app (a role with `backup:read` + `backup:update`) or designed as a standing decision. +- Backup timing, from the file stamps: starts ~23:46 UTC, takes ~4 minutes, and starts ~15 minutes + later each night (24 h after the last success, polled every 15 minutes). +- The sections below describe the state as measured before the cleanup. + +## The numbers + +Disk (`/data`, the root LV): **247.7 GB total, 74.9 GB free.** `statfs` used% = 69.75% on 2026-11-20. + +| What | Size | Growth | +| --- | --- | --- | +| `/data/backup/` | **~127 GB**, 30 files | net **~4.6–4.8 GB/day** (see below) | +| `parking.sqlite` | 6.58 GB | **~150–200 MB/day**, steady since 2026-10-09 | +| of which `snapshots` | **6.23 GB**, 50,629 rows | **~150 MB/day** (~1,200 images × ~122 KB) | +| of which `device_events` + indexes | 0.31 GB, 325,606 rows | ~7 MB/day | +| everything else | < 30 MB | negligible | + +The database is not what fills the disk. **The backups are, and the backups are big because of the +snapshots.** + +## Cause 1: daily full backups, uncompressed, on the same disk + +- [[backup-recovery]] writes a **full encrypted copy every night** (`backup.ts`). AES-GCM output is + incompressible and nothing compresses it first, so each file is as big as the DB (6.57 GB on + 2026-11-19). +- park-2 runs the code default retention, **keep-last 7 + one per day for 30 days**: 30 files. + Pruning works: the 2026-10-20 file was deleted on schedule on the night of 2026-11-19. +- **Steady growth anyway.** Each night adds today's copy and drops the copy from 30 days ago. + Today's copy is about 30 days of DB growth bigger than the one deleted, so the folder grows about + **4.6 GB/day now**, and about **6.2 GB/day once the copies being deleted come from after + 2026-11-20** (31 × 200 MB). +- Each run also writes a **plaintext copy to `os.tmpdir()`** before encrypting. In the container + that is the overlay, which is the same disk. It needs about 6.8 GB free for the length of the run. +- **The backups sit on the disk they protect.** The target is `/data/backup`, inside the same + volume as the DB. That gives no protection against the loss of the disk or the PC, which is the + scenario [[backup-recovery]] was designed for. It needs a separate disk or an off-box target. + +Forecast **if nothing else happened**: backups start failing **~2026-12-03** (no room for the +plaintext copy) and the disk is full **~2026-12-04**. The DB would stop accepting writes then, +including the signed ledger. + +## Cause 2: two-thirds of the snapshots are Car Wash "pass samples" + +On 2026-11-19 there were 1,299 snapshots: + +| Kind | Entry cam | Exit cam | Share | +| --- | --- | --- | --- | +| `pass:`: one frame per detected car, no session | 542 | 319 | **66%** | +| tied to a ticket, card or plate in the ledger | 239 | 199 | 34% | + +- Pass samples come from `anpr-entry.ts` `#recordPass` (commit `30a1180`, 2026-10-08, + [[vision-review-outbox]] §"Every car that passes"). The ANPR bridge stores the best frame of + **every** detected vehicle so the Car Wash module can sample it for the reviewer. +- **The review outbox makes its own blurred crop at queue time** (`review-outbox.ts`, + `makeReviewCrop` → `carwash_review_outbox.image`). After that, the pass snapshot is not read by + the outbox again. +- **Nothing deletes pass snapshots** except the disk-pressure valve below. They are about **105 MB + a day**, more than half of the DB's growth, and they are copied into every nightly backup. +- Ledger-tied snapshots are about one per signed event: 7,856 snapshots for 7,650 identities in + the 7 days to 2026-11-19. There is **no** multi-shot bug. +- The entry and exit cameras also fire on refused and held events (by design, [[entry-exit-points]] + §Refused entry/exit ALSO snapshots). + +## The hazard: the snapshot valve fires on 2026-11-21 + +`snapshot-retention.ts` ([[entry-exit-points]] §Retention) runs daily, 24 h after the container +start (so **~14:16 UTC**), plus **once at every container start**. When the disk is **≥ 70%** used, +it deletes the oldest snapshots until it estimates it has freed **10% of the disk** (~24.8 GB), never +below **500** rows. Then it runs `VACUUM`. + +- Tonight's backup takes the disk from 69.75% to about **71.7%**. The run on **2026-11-21 ~14:16 UTC** + will fire. +- **It deletes almost every snapshot.** The target (24.8 GB) is four times all the snapshots + (6.2 GB), so it stops only at the 500-row floor: about the **last 10 hours** of images. Ticketed + evidence goes with the pass samples. Older images survive only inside the encrypted backups. +- **It repeats daily.** Backups keep the disk above 70%, so every day it prunes to the floor and + logs "disk pressure is not from snapshots". Snapshot evidence older than about 10 hours stops + existing on the booth. +- **It is likely to freeze the server (estimated, not measured).** The delete loop is fully + synchronous on the main thread (better-sqlite3, no `await` inside it). It runs ~250 batches, and + each batch selects `ORDER BY captured_at` with `length(bytes)` over a table with **no index on + `captured_at`**. A single read-only pass of that kind over this table took several minutes from a + separate process on 2026-11-20. Then `VACUUM` rewrites the file on the same thread. Same failure + class as [[park-2-event-loop-stall]]: relay pulses, reader pushes and the booth UI wait behind it. +- Side effect: the DB drops to about 0.4 GB, nightly backups shrink, and the folder rotates down + over 30 days. **The disk would survive. The evidence and the booth's responsiveness would not.** + +**Do not restart the park-2 server container while the disk is ≥ 70%.** The valve runs at startup. + +## What to do, in order + +1. **Today (2026-11-20), before tonight's backup: lower backup retention** on Setup → Backup, for + example keep-last 7, keep-daily 7. Retention is read fresh each run, and `pruneOldBackups` runs + right after the new file is written, so tonight's run applies it. It should free roughly 90 GB and + take the disk to about 33%. **Check `df` on 2026-11-21 before 14:16 UTC.** +2. **Move the backup target off the data disk** (USB or SATA disk mounted by fstab and bind-mounted, or + SFTP), per [[backup-recovery]] §The target must be a bind-mounted host path. +3. **Stop storing pass samples permanently.** Options, to decide: + - delete the pass snapshot once the outbox has made its crop, or when the module does not sample it; + - give `pass:` rows a short age-based retention (for example 48 h); + - do not store a pass frame at all when the Car Wash module is off or sampling is 0. +4. **Fix the valve itself** (code, stage first): + - add an index on `snapshots(captured_at)`; + - make the delete loop yield between batches, or run it off the main thread; + - cap a run's target at what snapshots actually hold, and do not prune evidence when snapshots + are not the cause of the disk pressure; + - prune `pass:` rows before ledger-tied rows; + - `VACUUM` off-peak, not inside the request thread. +5. **Smaller backups:** compress before encrypting (gzip or zstd of a SQLite file usually shrinks it a + lot; the restore tool must then decompress), or the "exclude snapshots" option already noted on + [[backup-recovery]]. + +## Corrections from the code review (2026-11-20) + +- **The freeze is likely hours, not minutes (from the schema, not measured).** `bytes` precedes + `captured_at` in `snapshots`, so each batch's `ORDER BY captured_at` walks every remaining row's + blob pages. ~250 batches run back to back on the main thread. The server has `restart: always` + and the valve runs at startup, so a restart of a frozen booth re-enters it. +- **A backup run holds ~13 GB extra** (plaintext copy + encrypted file) until it prunes. +- **Step 1 lands near 37–40% used, not 33%**, and buys about seven weeks. +- **Compression will not shrink the backups** (step 5): ~95% of the DB is JPEG. Excluding + snapshots would, but backups are the only place old images survive a valve run, so it depends on + the evidence-retention decision below. +- **No threshold knob:** `SNAPSHOT_*` variables are not forwarded by `docker-compose.yml`. +- **A failed backup leaves a partial `.enc`** in the target and skips pruning; the partial file + counts as a backup for retention. +- **Lowering the code default retention** in `backup.ts` fixes park-2 with no DB or app access, if + its retention columns are empty (not read). Any deploy carries the commits since `73ada89`. + +## Open decisions + +- How long ledger-tied snapshots (entry and exit evidence) must be kept on the booth: an age, not + "until the disk is 70% full". Add this to [[open-questions]] #10. +- Whether pass samples are kept at all after the review crop. The camera large view (‹ › + through older and newer snapshots, `cb43ad7`) may show them; check before deleting. + +## How it was measured (read-only) + +- `df` and `ls` inside the container. +- `dbstat` per-table sizes. +- Per-day `count` and `length(bytes)` from `snapshots`. +- Snapshot identities joined against `ledger_events.identity`. +- All run with better-sqlite3 opened `readonly` in a separate `node` process inside the container + (`docker exec -i park-2-server-1 nice -n 19 node -`); the container has no `sqlite3` CLI. +- Full scans of `snapshots` take minutes; avoid them during busy hours. + +Related: [[backup-recovery]], [[entry-exit-points]], [[vision-review-outbox]], +[[park-2-event-loop-stall]], [[open-questions]]. diff --git a/wiki/concepts/vision-review-outbox.md b/wiki/concepts/vision-review-outbox.md index 0c189f2..c497755 100644 --- a/wiki/concepts/vision-review-outbox.md +++ b/wiki/concepts/vision-review-outbox.md @@ -69,7 +69,9 @@ plate or no plate. One sample per detection (the loop is one per car, joins slid module's `sampleEntry(deviceId)` **dedups per camera for 30 s** (`ENTRY_DEDUP_MS`): the pass sample and the ticket entry's read, seconds apart from the same camera, are one car. The plate box is handed over whenever the detector saw a plate, confident or not — it is what the crop -blurs. Pass snapshots ride the normal retention/pruning. Needs `anpr: true` and the per-camera +blurs. Pass snapshots ride the normal retention/pruning, which in practice means **nothing deletes +them** until the disk-pressure valve fires. On park-2 they are 66% of all snapshots (~860 a day, ~105 +MB a day) and the outbox no longer reads them once its crop is made; see [[park-2-disk-growth]]. Needs `anpr: true` and the per-camera auto-trigger on (the bridge bails before polling otherwise) — same gate as recognition today. An internet feed was considered the same day and kept OUT of the collector's ingest: licensed diff --git a/wiki/decisions/open-questions.md b/wiki/decisions/open-questions.md index e4079dd..e16d540 100644 --- a/wiki/decisions/open-questions.md +++ b/wiki/decisions/open-questions.md @@ -2,7 +2,7 @@ type: decision tags: [parking, decisions, open] sources: [parking-system-architecture] -updated: 2026-10-08 +updated: 2026-11-20 status: open --- @@ -84,6 +84,10 @@ procurement. (See [[parking-system-architecture]] §10.) _(Update 2026-06-29: pruning is now disk-pressure based — see [[entry-exit-points]]; and the settled #5 backup includes snapshot BLOBs by default, with a noted future "exclude snapshots" toggle since they dominate backup size — see [[backup-recovery]].)_ + _(Update 2026-11-20: reopened by [[park-2-disk-growth]]. The disk-pressure valve is the wrong + policy on a booth whose backups share the disk: it wipes all but 500 snapshots daily. Undecided: + an age-based retention for ledger-tied evidence, and whether Car Wash `pass:` samples are kept + after the review crop.)_ 11. **Appliance OS image → WebKitGTK version (Tauri dependency).** _(Raised by [[desktop-shell-tauri]], 2026-06-21; narrowed same day.)_ The chosen [[desktop-shell-tauri|Tauri v2 desktop shell]] renders through the **host's WebKitGTK**, not a diff --git a/wiki/index.md b/wiki/index.md index ba0326d..f8b0da6 100644 --- a/wiki/index.md +++ b/wiki/index.md @@ -103,6 +103,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. +- [[park-2-disk-growth]] — INCIDENT 2026-11-20 (open, deferred): nightly full backups on the data disk push park-2 past 70%, where the snapshot valve deletes all but 500 snapshots and likely freezes the server. Old backups deleted by hand (disk 29%); retention unchanged, 70% again ~2026-12-05. 66% of snapshots are Car Wash `pass:` samples nothing deletes. Code fixes wait. - [[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; phase 1 = the close only (dry run first); A→B/B→A/A↔B line editor in Setup built; relay maps per site; park-lab test plan. - [[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). diff --git a/wiki/log.md b/wiki/log.md index 6bb194a..afd373b 100644 --- a/wiki/log.md +++ b/wiki/log.md @@ -3759,3 +3759,28 @@ lost. Fixed (uncommitted) in `platform-ws.ts`: the plugin's commands are called own channel from the start, and early frames are held until the open. Not yet checked in the desktop app. Also recorded that both park-lab cameras now push to the dev machine. Updated [[desktop-shell-tauri]], [[camera-live-view]], [[passage-confirmation]]. + +## [2026-11-20] query | park-2 disk growth — backups, pass samples, and the snapshot valve + +User asked how long before park-2's disk fills (`parking.sqlite` 6.1 GB and growing). Measured +read-only on park-2: +- the disk is filled by `/data/backup` (30 nightly full, uncompressed copies on the same disk, + ~127 GB), not the DB; +- the DB grows ~150–200 MB a day, almost all `snapshots`, and 66% of those are Car Wash `pass:` + samples (`anpr-entry.ts` `#recordPass`) that nothing deletes; +- the disk is at 69.75%, so the disk-pressure snapshot valve fires 2026-11-21 ~14:16 UTC. It will + delete all but 500 snapshots daily, and its synchronous loop is likely to freeze the server. + +Corrected an earlier claim made in chat ("~6 photos per vehicle"): it is about one per ledger +identity plus the pass samples. Wrote [[park-2-disk-growth]]. Updated [[entry-exit-points]] +(contradiction: the valve is not a no-op), [[vision-review-outbox]], [[backup-recovery]], +[[open-questions]] #10, and the index. + +## [2026-11-20] query | park-2 disk growth — manual cleanup, fixes deferred + +Reviewed [[park-2-disk-growth]] against the code. The user deleted old backup files on the host: +six remain, disk at 29%, the valve is disarmed. Retention is unchanged (no app login on park-2), +so the disk reaches 70% again around 2026-12-05. The user deferred the code fixes until the +feature work on `stage` is deployable. Recorded the new state, the next deadline and the +corrections from the code review (freeze length, compression, no threshold knob, partial files) +on the page.