Skip to content

Commit 34af214

Browse files
authored
fix: owner-local dates and trimmed unit numbers (#1154)
Phase 66.3.1. After 18:00 CST, the database's UTC day is already tomorrow. Owner reports, dashboard windows, late status and reversal dates therefore ran a day ahead. Separately, unit numbers that differed only in surrounding whitespace could both exist on one property. ## What changes - **DATE-01:** the browser sends its local day as `p_today` to all 15 owner RPCs that read "today". `public.owner_local_day` accepts a day within one day of UTC and otherwise falls back to the UTC day. That day is part of every factory's query key, and `QUERY_CACHE_BUSTER` is v18. - **DATE-02:** `reverse_charge` and `reverse_receipt` date reversals on the owner's bounded day. - **DATE-03:** cron and quota functions keep the UTC day on purpose, documented in each body: - `expire_leases` (23:00 UTC = 17:00 CST, the same calendar day); - `generate_lease_rent_charges` (05:00 UTC; the charge dates come from the period, so none is wrong); - `queue_lease_reminders` (06:00 UTC = 00:00 CST, the same day); - `meter_esign_send` and `get_esign_usage_current_month` (the e-sign quota counts the UTC month, and the display matches the meter). - No schedule changes. - **UNIT-01:** `public.js_trim` trims exactly what JavaScript's `String.prototype.trim` trims. Triggers store `units.unit_number` and `properties.name` trimmed, and existing rows were backfilled behind a guard that stops on a collision (0 found). - **UNIT-02:** `units_property_unit_number_key` is rebuilt on `lower(js_trim(unit_number))` under the same name. - **Edge Functions:** `export-report` and `generate-pdf` read `today` from the request, falling back to UTC, and pass `p_today`. - **`db:types`:** now ignores the CLI's update notice, and the types are regenerated in the CLI 3.4.0 format. ## Migrations (already applied to production, 2026-12-02 CST) | File | Version | |------|---------| | owner_local_dates_dashboard | 20261203000149 | | owner_local_dates_analytics | 20261203000405 | | owner_local_dates_ledger_and_jobs | 20261203010229 | | js_trim_units_properties | 20261203022837 | The deployed client keeps working against them, because every new parameter has a default. Checks after the apply: - md5 of each stored body against the file: 24 of 25 match. `js_trim` holds its non-ASCII code points as literal characters instead of `\u` escapes, introduced by the apply transport; its behaviour is identical across 33 code points tested. - Grant sweep: matches the plan, with anon false everywhere. - A sweep for UTC-day reads finds only the documented exemption. - Rolled-back probes behaved as expected. - Integration tests: `rent-ledger-append-only` 10/10, `units-unique-number` 7/7, `anon-rpc-grants` 35/35. Chrome check at 20:39 CST (local 12-02, UTC 12-03): every owner-day request on 10 pages carried `p_today: "2026-12-02"`, and Reports > Expenses reads "Nothing spent Jan 1 to Dec 2, 2025". ## Known residuals - Comparisons between a timestamptz column and the owner's day still cut at UTC midnight. "newThisMonth" and "completedToday" are rendered nowhere; the 30-day maintenance-trend boundary can be up to 6 hours off. - `start_lease_ledger` uses `generate_lease_rent_charges`'s UTC month, so next month's charge can appear up to 6 hours early on a month's last evening. - The comment inside the applied `generate_lease_rent_charges` body says next month's charge can appear "up to 6 hours early". Via the 05:00 UTC cron it is at most 1 hour early for Central owners; 6 hours applies only to `start_lease_ledger`, and more in western zones. It is left as is, because correcting it would need a production write. - `formatDate` prints timestamptz values on their UTC day across about 27 files (tenants, inspections, applications, work orders). That is recorded for a follow-up phase. ## Review Four review cycles, with every finding fixed on this branch: - **CI-only test failures:** four owner-day tests passed only on a Central-time host. The unit suite is now pinned to America/Chicago in `vitest.config.ts`, with a guard test. - **UTC dates owners saw:** the `/reports/generate` file name, the documents zip name, the dashboard's expiring-leases widget, and the lease template's dates now use the owner's local day. - **Test steadiness:** a reversal-date integration test no longer depends on whether a run crosses UTC midnight. - **Comments:** comments that claimed things the code does not do are corrected. The final cycle found no P0 or P1. The owner waived the second consecutive clean cycle. ## After merge Redeploy the two Edge Functions from `main` with explicit slugs: ``` SUPABASE_ACCESS_TOKEN=… bun scripts/deploy-edge-functions.ts export-report generate-pdf ``` Then verify with `get_edge_function`. Until that deploy, the live functions call the RPCs without `p_today`, which is compatible. Rollback order: roll Vercel back first, and never roll the database back while the new client is live. [hudsor01]
2 parents 7c430f4 + 2e06999 commit 34af214

161 files changed

Lines changed: 15751 additions & 614 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/migration-replay.yml‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ on:
5858
- scripts/migration-replay-owner-figures.sql
5959
- scripts/migration-replay-blog-banlist.sql
6060
- scripts/migration-replay-subscription-write-guard.sql
61+
- scripts/migration-replay-local-day-and-trim.sql
6162
# The negative controls, and the shared result module: a change that
6263
# weakens a control has to run the gate it guards. (The result module's
6364
# own controls are in scripts/assertion-result.test.ts, because a green
@@ -292,6 +293,29 @@ jobs:
292293
printf '%s\n' "$result"
293294
bun scripts/assert-migration-replay.ts subscription-write-guard <<<"$result"
294295
296+
- name: Assert owner RPCs follow the owner's day and js_trim trims unit numbers
297+
run: |
298+
set -euo pipefail
299+
# 20261203000149..20261203010229 re-create fifteen owner RPCs with a
300+
# p_today argument read through public.owner_local_day, which keeps
301+
# the browser's day within one day of the UTC day and falls back to
302+
# the UTC day otherwise; 20261203022837 adds public.js_trim, trims
303+
# unit numbers and property names in BEFORE triggers and rebuilds
304+
# units_property_unit_number_key on lower(js_trim(unit_number)).
305+
# Postgres checks EXECUTE on that index expression as the writing
306+
# role, so without js_trim's grant to authenticated every unit
307+
# insert from the app would fail. The fixture seeds a ledger for the
308+
# seeded owner A (so it runs after the cast step), calls the clamp,
309+
# get_financial_overview and reverse_receipt with p_today inside and
310+
# outside the bound, inserts a unit and a property as owner A, reads
311+
# every new signature's EXECUTE grants, prints ONE JSON line and
312+
# rolls back. The expected outcome of every case lives in
313+
# scripts/migration-replay-assertions.ts. A herestring, as above.
314+
result=$(docker exec -i supabase_db_tenant-flow psql -U postgres -X -q -t -A \
315+
-v ON_ERROR_STOP=1 < scripts/migration-replay-local-day-and-trim.sql)
316+
printf '%s\n' "$result"
317+
bun scripts/assert-migration-replay.ts local-day-and-trim <<<"$result"
318+
295319
- name: Stop the stack
296320
if: always()
297321
run: supabase stop --no-backup || true

‎.planning/REQUIREMENTS.md‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,11 @@ Source: product audit of the app, 2026-11-30 (owner-approved scope). Out of scop
181181
- [x] **FIX-04**: Analytics overview labels use the app's terms (charges, balance, tenants)
182182
- [x] **FIX-05**: An active lease's detail page offers Renew and Terminate
183183
- [x] **FIX-06**: The printable Rental Application form claims no screening feature the product does not offer
184+
- [ ] **DATE-01**: Owner-facing figures bounded by "today" use the owner's local calendar day (sent by the browser), never the server's UTC day
185+
- [ ] **DATE-02**: A charge or receipt reversal is dated on the owner's local day
186+
- [ ] **DATE-03**: Server-side jobs keep a documented UTC day, and no owner RPC reads `current_date` for the owner's day
187+
- [ ] **UNIT-01**: Unit numbers and property names are stored trimmed by one shared SQL trim that matches `String.prototype.trim`; existing rows normalized
188+
- [ ] **UNIT-02**: The units uniqueness index and the lease lifecycle trigger use that shared trim
184189
- [ ] **EXP-01**: Owner can record an expense against a property (optionally a unit) without a maintenance request
185190
- [ ] **EXP-02**: Expenses carry a category from a landlord-cost set ready to map to Schedule E lines
186191
- [ ] **EXP-03**: Owner can make an expense recur (monthly/quarterly/yearly)
@@ -339,6 +344,11 @@ Populated by roadmap creation (2026-07-19). Every v10 requirement maps to exactl
339344
| FIX-04 | Phase 66.3 | Complete |
340345
| FIX-05 | Phase 66.3 | Complete |
341346
| FIX-06 | Phase 66.3 | Complete |
347+
| DATE-01 | Phase 66.3.1 | Pending |
348+
| DATE-02 | Phase 66.3.1 | Pending |
349+
| DATE-03 | Phase 66.3.1 | Pending |
350+
| UNIT-01 | Phase 66.3.1 | Pending |
351+
| UNIT-02 | Phase 66.3.1 | Pending |
342352
| EXP-01 | Phase 66.4 | Pending |
343353
| EXP-02 | Phase 66.4 | Pending |
344354
| EXP-03 | Phase 66.4 | Pending |

‎.planning/ROADMAP.md‎

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ None of the renumbered phases had a directory, plan, summary or PR, so nothing s
3838
- [x] **Phase 66: Rental Application Intake** - Public `/apply/[token]` intake (no accounts, no SSN, no screening) with owner review queue + convert-to-tenant (completed 2026-08-15, #966)
3939
- [x] **Phase 66.1: Postgres-backed rate limiting with trusted client-IP forwarding** *(INSERTED)* - Move the limiter off Upstash into Postgres, fail closed, with a real per-client key on `/apply/[token]` (completed 2026-08-22, #967)
4040
- [x] **Phase 66.2: Tailwind v4 and shadcn/ui canonical remediation** *(INSERTED)* - Fix the live styling defects (magenta secondary, mobile control deformation, unreadable dark-mode surfaces) at the root, then canonicalize tokens, classes and vendored shadcn components, and move the owner shell to the canonical shadcn Sidebar. One PR.
41+
- [x] **Phase 66.3: Lease and analytics fixes** *(INSERTED)* - Lease detail Terms/Timeline/Renew/Terminate, analytics trends and labels, printable application without screening claims (completed 2026-12-01, #1142; follow-ups #1153)
42+
- [ ] **Phase 66.3.1: Owner-local dates and unit whitespace** *(INSERTED)* - Owner date math uses the owner's local day instead of UTC; unit numbers and property names normalized on write
43+
- [ ] **Phase 66.4: Record any expense** *(INSERTED)* - Property-level expenses with categories, recurring entries and receipts
44+
- [ ] **Phase 66.5: Rent roll and late-rent alerts** *(INSERTED)*
45+
- [ ] **Phase 66.6: Security deposit tracking** *(INSERTED)*
46+
- [ ] **Phase 66.7: Bank statement CSV import** *(INSERTED)*
4147
- [ ] **Phase 67: Tenant Communication Log** - Owner-side comms timeline: logged notes/calls + auto-logged suppression-honoring email from the app
4248
- [ ] **Phase 68: State-Aware Notice Library** - Counsel-reviewed, state-aware notices on the lease-template rails, saved to the vault with a service date (curated launch states)
4349
- [ ] **Phase 69: Compliance & Key-Date Tracking** - Track per-property key dates (insurance/license/tax/inspection) with reminders through the shared reminder rail
@@ -368,6 +374,35 @@ Plans:
368374

369375
**UI hint**: yes
370376

377+
### Phase 66.3.1: Owner-local dates and unit whitespace (INSERTED)
378+
379+
**Goal**: Every "today", "this month" and "year to date" an owner sees is the owner's own calendar day, not the database server's UTC day (which runs a day ahead after 6 PM CST). Unit numbers and property names are stored trimmed, so "4B" and "4B<TAB>" are the same unit.
380+
**Depends on**: Phase 66.3 (merged #1142, follow-ups #1153)
381+
**Requirements**: DATE-01, DATE-02, DATE-03, UNIT-01, UNIT-02
382+
**Source**: Chrome verification of 66.3 (2026-11-30: Reports → Expenses read "Jan 1 to Dec 1, 2025" at 18:45 CST) and the #1142/#1153 reviews.
383+
**Success Criteria** (what must be TRUE):
384+
1. At 18:00–23:59 CST, every owner-facing figure bounded by "today" (dashboard KPIs and trends, collection rate, analytics and report periods, expenses year to date and year over year, ledger summary and late status) uses the owner's local date, sent by the browser; no owner RPC relies on Postgres `current_date` or `now()::date` for the owner's day
385+
2. Reversing a charge or receipt dates the reversal on the owner's local day
386+
3. Server-side jobs (expire_leases, rent charge generation, reminders) keep their UTC schedule, with the chosen day documented
387+
4. Unit numbers and property names are trimmed on every write by one shared SQL function that trims exactly what JavaScript's `String.prototype.trim` trims; existing rows are normalized
388+
5. The units uniqueness index treats "4B" and "4B<TAB>" as the same unit, and the lifecycle trigger uses the shared trim function
389+
**Plans**: 13 plans
390+
391+
Plans:
392+
- [x] 66.3.1-01-PLAN.md — Migration A1: owner_local_day clamp helper + the five dashboard-family RPCs with p_today, V-3 migration guard, replay signature strings
393+
- [x] 66.3.1-02-PLAN.md — Migration B: js_trim (granted to authenticated/service_role), trim triggers, guarded backfill, units index on lower(js_trim()), lifecycle trigger; parity and units integration tests
394+
- [x] 66.3.1-03-PLAN.md — V-2 p_today source-scan guard, useLocalToday hook, Reports -> Expenses YTD fix, cache buster v18, Edge resolveOwnerToday + export/PDF day
395+
- [x] 66.3.1-04-PLAN.md — Migration A2: expense summary, financial overview, revenue/occupancy trends, maintenance and property-performance RPCs with p_today
396+
- [x] 66.3.1-05-PLAN.md — Migration A3: collection rate, ledger summary, reversals with p_today; UTC-day comments on the server jobs; V-3 completeness; reversal-date integration test
397+
- [x] 66.3.1-06-PLAN.md — Dashboard payload, revenue chart, collection rate and rent ledger (summary, late badges, reversals) on the owner's day
398+
- [x] 66.3.1-07-PLAN.md — Financial statements, report builder and report leaves on the owner's day
399+
- [x] 66.3.1-08-PLAN.md — Analytics pages and the property Performance card on the owner's day
400+
- [x] 66.3.1-09-PLAN.md — Year-end/tax-documents and financial-analytics page/export twins with p_today; Deno handler tests
401+
- [x] 66.3.1-10-PLAN.md — Replay fixture local-day-and-trim (authenticated unit insert, day clamp, reversal date, ACLs), assertion, CLI, workflow step, mutation-sweep rows
402+
- [x] 66.3.1-11-PLAN.md — V-2 made absolute, full gates, local migration replay, Aikido scan
403+
- [x] 66.3.1-12-PLAN.md — Owner-gated production apply (A1-A3, B), ledger reconcile, md5 fidelity, ACL/DATE-03 sweeps, rolled-back probes, db:types fix + regen, integration runs
404+
- [ ] 66.3.1-13-PLAN.md — Claude in Chrome verification, owner go-ahead PR, CI + perfect-PR loop, post-merge export-report/generate-pdf deploy
405+
371406
### Phase 66.4: Record any expense (INSERTED)
372407

373408
**Goal**: An owner can record every rental cost, not only repairs: property-level expenses with a category, optional unit/lease link, recurring entries and receipt attachments, so net income and the tax summary count every cost.
@@ -506,7 +541,7 @@ Plans:
506541
## Progress
507542

508543
**Execution Order:**
509-
Phases execute in this order: 52 → 53 → 54 → 55 → 56 → 65 → 66 → 66.1 → 66.2 → 66.3 → 66.4 → 66.5 → 66.6 → 66.7 → 67 → 68 → 69 → 70 → 71 → 72 → 73. Each phase branches only after the previous phase's PR is merged to main. This is now plain ascending order — Phase 65 was split out of Phase 56 on 2026-07-26 and briefly sat out of sequence, which the 2026-08-04 renumber of 57-64 → 66-73 resolved. The decimal phases 66.1 and 66.2 were inserted as urgent work; GSD sorts decimals numerically, so ascending order is still execution order.
544+
Phases execute in this order: 52 → 53 → 54 → 55 → 56 → 65 → 66 → 66.1 → 66.2 → 66.3 → 66.3.1 → 66.4 → 66.5 → 66.6 → 66.7 → 67 → 68 → 69 → 70 → 71 → 72 → 73. Each phase branches only after the previous phase's PR is merged to main. This is now plain ascending order — Phase 65 was split out of Phase 56 on 2026-07-26 and briefly sat out of sequence, which the 2026-08-04 renumber of 57-64 → 66-73 resolved. The decimal phases 66.1 and 66.2 were inserted as urgent work; GSD sorts decimals numerically, so ascending order is still execution order.
510545

511546
| Phase | Plans Complete | Status | Completed |
512547
|-------|----------------|--------|-----------|
@@ -520,6 +555,7 @@ Phases execute in this order: 52 → 53 → 54 → 55 → 56 → 65 → 66 → 6
520555
| 66.1 | 5/5 | Complete | 2026-08-22 |
521556
| 66.2 | 39/39 | Complete | 2026-11-09 |
522557
| 66.3 | 12/12 | Complete | 2026-12-01 |
558+
| 66.3.1 | 12/13 | In Progress | - |
523559
| 66.4 | 0/TBD | Not started | - |
524560
| 66.5 | 0/TBD | Not started | - |
525561
| 66.6 | 0/TBD | Not started | - |

‎.planning/STATE.md‎

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
gsd_state_version: 1.0
33
milestone: v10.0
44
milestone_name: Claims Integrity + Canonical Feature Expansion
5-
status: ready_to_plan
6-
last_updated: "2026-12-01T03:10:00.000Z"
7-
last_activity: 2026-12-01
8-
stopped_at: "Phase 66.3 merged 2026-12-01 as #1142 (883862c2c; lease lifecycle trigger live as 20261201004013; export-report v153 + generate-pdf v148 redeployed). Owner waived the last two clean review cycles after 4. Follow-ups: ledger reversal dates and unit-label trim applied as 20261201125304 (PR #1153); the activity entity index already existed (idx_activity_entity_created_at). Still open: the UTC current_date drift (to be its own phase). Next: merge #1153, then /gsd:discuss-phase 66.4."
5+
status: executing
6+
last_updated: "2026-12-03T02:45:00.000Z"
7+
last_activity: 2026-12-02
8+
stopped_at: "Phase 66.3 merged 2026-12-01 as #1142; follow-ups merged as #1153 (7c430f43f; migration 20261201125304). Phase 66.3.1 (owner-local dates and unit whitespace) inserted and planned 2026-12-01 (13 plans, 8 waves, checker passed, 0 blockers). Executing 66.3.1 since 2026-12-02: waves 1-7 (plans 01-12) done; the four migrations are live in production (20261203000149, 20261203000405, 20261203010229, 20261203022837), types regenerated, the three integration files pass. Next: plan 13 (Chrome check, owner go-ahead PR, merge, export-report and generate-pdf deploy)."
99
progress:
10-
total_phases: 21
10+
total_phases: 22
1111
completed_phases: 10
12-
total_plans: 111
13-
completed_plans: 111
14-
percent: 48
12+
total_plans: 124
13+
completed_plans: 123
14+
percent: 45
1515
---
1616

1717
<!--
@@ -65,13 +65,13 @@ See: .planning/PROJECT.md
6565

6666
**Core value (v10.0):** Every claim sold on the marketing surface is delivered end-to-end in the product, the built-but-unshipped backend becomes user-facing features, and the canonical landlord feature set ships within Next.js 16 idioms — extending, never violating, the landlord-only / no-rent-facilitation / tenants-are-records positioning. Grounded in the 2026-07-19 full feature audit (4 confirmed claims gaps + orphaned backend + canonical feature roadmap).
6767

68-
**Current focus:** Phase 66.4 — record any expense (next to discuss)
68+
**Current focus:** Phase 66.3.1 — owner-local dates and unit whitespace (planned; next to execute)
6969

7070
## Current Position
7171

7272
Phase: 66.3 (lease-and-analytics-fixes) — COMPLETE, merged 2026-12-01 as #1142; follow-ups PR #1153
7373
Plan: 12 of 12
74-
Status: Next is Phase 66.4 (discuss). The UTC current_date drift is to become its own phase.
74+
Status: Phase 66.3.1 planned 2026-12-01 (13 plans, 8 waves); next is /gsd:execute-phase 66.3.1, then Phase 66.4.
7575

7676
Phase 66.2 (history, merged 2026-11-09 as #1057):
7777
Status: PR open for the merge gates; the owner merges (2026-11-09). Re-frozen after perfect-PR
@@ -373,3 +373,4 @@ deliberately did NOT apply (`56-UI-SPEC.md:261`).
373373
- Phase 66.5 inserted after Phase 66.2: Rent roll and late-rent alerts
374374
- Phase 66.6 inserted after Phase 66.2: Security deposit tracking
375375
- Phase 66.7 inserted after Phase 66.2: Bank statement CSV import
376+
- Phase 66.3.1 inserted after Phase 66.3: Owner-local dates and unit whitespace (URGENT; UTC current_date drift found in 66.3 Chrome verification, unit whitespace from the #1153 review)

0 commit comments

Comments
 (0)