Documentation
Physical keys are the literal bridge between our digital software and a real-world property. This guide explains how RAIA (Real estate Artificial Intelligence Agent) tracks every key's physical location (like box numbers and hooks) and how it r
Physical keys are the literal bridge between our digital software and a real-world property. This guide explains how RAIA (Real estate Artificial Intelligence Agent) tracks every key's physical location (like box numbers and hooks) and how it r
AppSheet Keys Sync & Custody
Physical keys are the literal bridge between digital systems and real-world properties. This guide explains how RAIA (Real estate Artificial Intelligence Agent) tracks every key's location and runs automated nightly syncs with legacy MySQL systems.
Physical keys are the literal bridge between our digital software and a real-world property. This guide explains how RAIA (Real estate Artificial Intelligence Agent) tracks every key's physical location (like box numbers and hooks) and how it runs an automated sync with legacy MySQL systems every single night to ensure we never lose track of who has access to our assets.
A.5 Continuous AppSheet Sync & Physical Key Custody
Appendix Case StudyIn a professional letting agency, physical key tracking is a massive operational vulnerability and a frequent source of human friction. If keys are unaccounted for, check-ins stall, emergency contractors are locked out, and the landlord's asset security is severely compromised.
Under the **Sovereign Identity Tenancy Protocol (SITP)**, RAIA™ (Real estate Artificial Intelligence Agent) completely replaces manual paper logs and static AppSheet entries with a fully audited, real-time database custody model. This specification outlines the database design of the physical custody tables, the nightly continuous sync pipeline bridging legacy Cloud SQL systems, and the multi-channel interface allowing staff to run key audits natively inside Telegram.
1. Nightly AppSheet Sync & Audit Pipeline
Our synchronization architecture operates as a secure, one-way bridge from legacy AppSheet Google Cloud SQL (MySQL) tables directly to our production Supabase PostgreSQL instance. Below is the active data ingestion and state verification pathway:
2. Cryptographic & Relational Database Schemas
In the database layer, physical keys are divided into two primary logical concerns: **Identity Records** (static, immutable attributes of the hardware) and **Custody Logs** (the dynamic chronological log of transactions).
tbl_keys (Static Identity)
Stores the core registration data for each physical key/fob. Key PIN codes are encrypted and isolated at this layer.
tbl_keys_log (Dynamic Transactions)
An append-only historical log tracking every check-in, check-out, loss, or transfer event of a key.
Repository Code
The live codebase implementation for this specification sits within the following repository folder:
To avoid slow queries scanning millions of historical logs, Supabase leverages the vw_key_current_state materialised database view. This view partitions tbl_keys_log by key_id, ordering by action_at DESC to instantly compile the absolute current state of any physical key: its action, box number, hook number, holder name, and last updated timestamp. This view serves as the dynamic context injection point for RAIA's LLM reasoning core.
3. Automated Sync Guardrails & Security Shielding
ADR-224 ComplianceDuring the continuous sync execution, our sync engine implements three active security shields and logic boundaries:
Shield A: Zero-Leaks Pin Protection
While raw physical lockbox codes and physical door PINs (Code) are ingested into tbl_keys to allow emergency key releases via encrypted, transient MFA channels, **PIN codes are strictly excluded from all transaction logs (tbl_keys_log) and events**. This ensures that even if a logging stream is intercepted, a property's access PIN is never exposed in plaintext telemetry logs.
Shield B: PostgREST Pagination Protection
The Supabase PostgREST data layer caps all queries to **1,000 maximum rows**. Standard, un-paginated requests silently truncate data. Our sync engine incorporates a recursive, paginated `fetchAll()` loop. This structural shield was deployed specifically to recover from a silent bug that had stranded 80% (~1,600 rows) of active keys in legacy databases.
Shield C: State Integrity Protection (Anti-Downgrades)
Since AppSheet is a legacy data environment where humans make mistakes, the nightly sync engine incorporates an active PROTECTED_STATUSES gate. When syncing service-level agreements, the sync engine will **never overwrite or downgrade** modern client statuses (like signed safety records or completed compliance markers) back to legacy states like in_discussion.
4. Multi-Channel Conversational Audit (Telegram Interface)
Instead of logging into a heavy portal or reading database spreadsheets, staff interact with physical key custody data directly via **Telegram voice notes** or text. Below is the operational execution path for a dynamic key audit:
📞 Conversational Ingress
A staff member records a Telegram voice note: "Are there any keys checked in for Latymer Court?". Vercel routes this audio to Nginx Port 80, which reverse-proxies it to the local FastAPI faster-whisper container on Port 9119.
⚙️ Dynamic View Query
RAIA's orchestrator identifies the property context (Latymer Court) and queries the database view vw_key_current_state filtering for the corresponding asset ID. The state compiler calculates total keys, checked-in keys, and current locations.
📣 Native Voice Feedback
RAIA (Real estate Artificial Intelligence Agent) synthesizes a Gemini TTS audio stream, wraps the raw PCM buffer in a compliant 44-byte WAV RIFF header, and delivers a native voice bubble to Telegram: "Latymer Court has 1 key checked in at the office in Box 8 on Hook 17."
5. Pipeline Ingestion & Sync Telemetry
tbl_pipeline_runs
To maintain absolute system health and transparency, every nightly synchronization run is tracked inside the central tbl_pipeline_runs table. The engine inserts a dedicated row (pipeline='appsheet_sync') documenting execution durations, counts, skipped records, and errors in a structured JSONB breakdown payload.
{
"pipeline_run_id": "8fa8bf6d-2e74-4b53-b05b-9d4f58c735d4",
"pipeline": "appsheet_sync",
"status": "completed",
"duration_seconds": 12.4,
"breakdown": {
"addresses_processed": 2455,
"assets_updated": 3,
"services_inserted": 0,
"keys_upserted": 2038,
"keys_skipped_no_asset_match": 127,
"keys_log_inserted": 12831,
"keys_log_skipped_no_key": 641,
"keys_skipped_unmatched_orgs": 59
},
"created_at": "2026-06-03T00:00:12.450Z"
}