Infrastructurepattern
Defensive sheet-write playbook
"Wrote to row 412 instead of 109" because a stray cell shifted append(). Four explicit defences against the classic shared-sheet failure modes.
What
A bundle of four small defenses that together prevent the classic "automated write to shared sheet went sideways" failure mode:
- Use
values().update()with an explicit row range, neverappend().append()jumps past stray cells in non-primary columns and mis-aligns rows. Compute the last data row from the primary column (e.g.,Name) only. - Set
valueInputOption=RAW, neverUSER_ENTERED. User-controlled display names like=HYPERLINK(...)get parsed as formulas underUSER_ENTERED— classic formula-injection class. - Four-rule dedup before writing (first-match wins): (a) handle match (normalized: lowercased, leading
@stripped); (b) exact full-name match (case-insensitive, whitespace-collapsed); (c) multi-word primary-name match — both sides ≥2 tokens AND token sets equal; (d) single-word match only if Org tokens overlap ≥1. Anything matching rule (d) with weak Org overlap surfaces asambiguous, not silently dropped. - Auto-discovery of existing sessions / configs in common paths before nagging the user to re-login. Print reuse instructions.
Why it matters
Each defense was learned the hard way. The first run of a founder-discovery sheet wrote to row 412 instead of row 109 because of a stray cell in another column. Telegram display names like =HYPERLINK(...) would have parsed as formulas. "Konrad" + "Konrad Smith" caused the most common dedup false positives in test runs. And the "ugh, I have to re-login from scratch" friction was killing onboarding.
End-to-end
- Replace any
values().append()calls withvalues().update(range=...). Compute the range explicitly from the primary column. - Audit every call site for
valueInputOption; default toRAW. - Implement dedup as four ordered rules; emit
_deduped.csv,_dropped.csv(with reason),_ambiguous.csv(treat as new unless user confirms). - In your preflight script, auto-scan for existing sessions/configs in
~/.config/,~/.local/share/,~/Documents/. If found, print the copy command for reuse.
Gotchas
- Reusing a colleague's service-account JSON authenticates as the colleague, not you. Every installer runs the setup script on their own machine and shares the sheet with their own service-account email.
Tools
- Google Sheets API client (or Notion / Linear equivalent)
- Service-account JSON (one per installer; never shared)
← All casesB-075