Reconcile stale Fathom media imports

Merged
EH
2mo ago
+1416-57

Stack

  1. #25432 — Fathom media storage foundation
  2. #25433 — Asynchronous Fathom media import
  3. #25434 — Local recovery and disconnect cleanup

Supersedes closed #25337. All changes are inside the Fathom app; no Twenty server, core, or SDK changes.

Scope

Recover known local work, not provider history. Review against #25433.

  • Daily recovery scans active-account CallRecordings from the last seven days that have been unchanged for at least 30 minutes.
  • Fix each run's cutoff times and use ID-keyset pagination, one 200-record page per job. Persist continuation state and drain the eligible cohort instead of repeatedly stopping at the same 400-record prefix.
  • Resume a saved download or request missing media; complete settled records with snapshot-guarded writes.
  • Queue disconnect cleanup independently of the hook. Recheck account inactivity on each page and use owner/ID/updatedAt guards.
  • Clean up disconnected-account local records regardless of age, with a daily orphan fallback if hook enqueueing fails. Finish transcript-bearing records; mark unfinished records without a transcript FAILED. Empty transcript/media arrays use the same semantic classification as normal imports.

No Fathom recording-list polling, recurring provider backfill, edit detection, or reconciliation of old active-account history. Historical imports remain explicit backfill work. Disconnect cleanup is eventual, not an atomic barrier at the instant of disconnect.

Review follow-up

Fixed historical-prefix starvation, the arbitrary two-page cap, import-order nits, oversized broad disconnect mutations, partial cleanup failure, and cleanup durability. Removed redundant NULL predicates that disagreed with parsed empty arrays and could cause endless cleanup requeueing.

Verification

Independently verified on the complete stack: typecheck, lint, 117 unit/real-HTTP tests across 23 files, and application build (30 files).

Added a real deployed-function/database regression for disconnected records with empty transcripts and null/empty media. It typechecks but was NOT run locally because Docker is unavailable; CI integration verification remains required. Pure planner tests cover recovery and disconnect outcomes. No service-mock suites or code comments added.

Fresh Twenty review follow-up: replace the repeated cleanup mutation scaffold with five explicit update descriptors and one execution loop; share the record snapshot reference type. An independent review confirmed unchanged guards, updates, ordering, and continuation behavior.

Review size: 779 non-test additions.