[factory] Recover babysitters after PR snapshot failures

Closed
KH
4mo ago
+574-18

Summary

  • retry PR-open snapshot reads with exponential backoff, visible exhaustion, and periodic dead-letter redrive
  • reconcile in-flight issues against open same-repository Factory PRs and adopt ownerless PRs without waiting for another webhook
  • warn on the first unowned event, escalate repeats, and publish daemon counters through factory status
  • cover transient read recovery, exhausted reads, unowned-event visibility, and the observed cloud#3021 / cloud#3024 identity shape

Verification

  • npm run build
  • npm run featuremap:check
  • npm test -- --reporter=dot (83 files, 1,557 tests)

Fixes #243


Summary by cubic

Recovers babysitters after PR snapshot read failures and adopts ownerless Factory PRs without waiting for webhooks. Previously, a missed or unreadable PR-open snapshot dropped routing and left the PR unowned; now we retry with backoff, dead-letter on exhaustion, and a periodic reconcile redrives or adopts the PR to restore ownership. Addresses the requirements in Linear 243.

Key changes

  • Retries PR-open snapshot reads with exponential backoff; dead-letters on exhaustion and redrives them during the reconcile sweep. Adds counters and structured logging for failures, retries, dead-letters, and recoveries.
  • Adds a periodic reconcile that scans in-flight issues and adopts open, non-draft Factory PRs without owners. Adoption requires a factory/ head ref that matches the issue or a strong same-repo title match; on adoption, clears unowned-event counters and dead letters.
  • Tracks unowned PR events: warn on first occurrence, escalate at the 3rd and every 10th recurrence; counts escalations.
  • Surfaces daemon counters via the heartbeat and merges them into factory status output; heartbeat counters take precedence when the CLI runs out-of-process.
  • Extends PR resolution to include a matchScore so reconcile can safely adopt PRs when title evidence is strong even if branch numbers differ.

Rollout

  • No migration required. Monitor new counters in factory status for snapshot read failures, retries/dead-letters, unowned-event occurrences, and orphan adoption.