Synthetic CRM repair handoff
Implementation with AI coding tools, tests and written handoff. All supplied leads are fictitious.
Local run and acceptance
- Use Node 20+ in this folder. No packages or network are required.
- Run
node tests/run.cjs; require 17 passed and 0 failed. Baseline defect assertions are intentionally passing tests. - Run
node demo.cjs. Inspect the CSV, JSON summary and JSONL log inevidence/. - Confirm 8 scanned, 3 added, 2 duplicates, 3 rejected, final 4 leads and replay 0 additions. Confirm the owner note and formula are unchanged.
- Review rejected rows by source row and code. They are not silently repaired or removed from the inbox.
Optional client-controlled staging, not performed here
- Duplicate the target spreadsheet and save its current bound script and trigger inventory. Export the affected data before changes. Disable competing automation for the staging window.
- Create sheets
InboxandLeadswith the exact fixture headers. Map automation-owned fields to A:F; G onward remain manual. The script must be bound to the intended spreadsheet. - Copy only
after/Code.gsinto the staging bound script. Confirm timezone and limits in CRM_DEFAULTS. Do not install the broken baseline. - Run
runCrmDryRun()manually; review structured execution logs and planned counts. It writes neither sheet values nor the cursor. It does emit diagnostic logs. - After owner approval of staging results, manually run
runCrmRepair(). Inspect the values, retained notes/formulas and logs. Run it again to test replay. - If scheduled execution is wanted, the client creates one appropriate installable trigger for
runCrmRepairand reviews its permissions. This demo does not install or delete triggers.
Recovery and rollback
A service failure propagates with a RUN_FAILED code, while the script releases its lock. Wait until the platform recovers, then rerun; it scans existing output before continuing from the last committed cursor. If a write succeeded but saving the cursor failed, the existing output prevents duplicate additions. No blanket success is logged for a failed run.
The script property synthetic_crm_cursor_v1 is the zero-based count of processed Inbox data rows. Do not reset it casually. To replay corrected source rows in a staging copy, disable triggers, back up both sheets and properties, set this cursor to 0, dry-run, inspect output-based deduplication and then run explicitly. This sample does not update existing leads.
To roll back a staging repair: disable its trigger first, restore the saved script, restore the spreadsheet copy or its version containing data and formulas, and restore the cursor consistent with that data. Restore the saved trigger configuration only after confirming the old path is safe. Avoid deleting all script properties or triggers; unrelated automations may use them. The broken before/Code.gs is evidence only, not an operational rollback recommendation.
Known operating boundaries
Append-only inbox; one spreadsheet-bound script; default 5,000-row caps; timezone-aware text format; one lead per normalized email. The lock cannot coordinate unrelated scripts or human edits. Pre-existing duplicate CRM records stop the run. Logs record rejected source rows but retain no contact values. Tests simulate Google services and do not constitute live Google acceptance.