Skip to content

fix: retry link previews after temporary failures - #160

Merged
brendt merged 1 commit into
dev-null-sh:productionfrom
xHeaven:fix/link-preview-retries
Oct 16, 2026
Merged

brendt merged 1 commit into
dev-null-sh:productionfrom
xHeaven:fix/link-preview-retries

Conversation

@xHeaven

@xHeaven xHeaven commented Oct 15, 2026

Copy link
Copy Markdown
Member

Problem

UpdateLinkPreview set fetched_at whenever a fetch threw, including connection errors, timeouts, and unexpected errors, and it treated 5xx responses like any other unsuccessful response. UnfurlLink skips previews that already have fetched_at, so a short outage on the linked site lost the card permanently.

Behavior now

Permanent outcomes are still marked as fetched with no metadata and never retried:

  • a non-public address (or a host that resolves to one)
  • too many redirects
  • non-HTML content
  • 4xx responses other than 429

Transient outcomes are retried by the queued job with backoff: connection errors, timeouts with no partial body, 5xx, 429, and unexpected errors. UnfurlLink now has 3 tries with a 1-minute and then a 10-minute backoff. If the last attempt also fails, failed() marks the preview as fetched with no metadata, so it isn't retried again.

Implementation

  • UpdateLinkPreview::handle() no longer catches anything. On a 5xx or 429 it calls $response->throw(). A ConnectionException was already rethrown by get(), and a body that arrived before a timeout cut it off is still used. Anything else that throws goes to the queue as-is.
  • UnfurlLink now uses #[Tries(3)] and #[Backoff([60, 600])], the same pattern as SyncGitHubSshKeysJob, and has a failed() hook. No scheduler is needed.

Validation

  • Tests were written first and failed against the old code. Now green: tests/Unit/Actions/UpdateLinkPreviewTest.php, tests/Unit/Jobs/UnfurlLinkTest.php, tests/Unit/ArchTest.php, tests/Unit/Actions/CreateCommitTest.php, tests/Unit/Models/LinkPreviewTest.php (116 tests).
  • The job tests run the real database queue worker (queue:work --once) with time travel. They check that a retry doesn't run before the backoff ends, that a later success stores the metadata, and that the preview is marked fetched only after the third failure.
  • pint, rector --dry-run and phpstan pass on the touched scope. Type coverage is 100%.
  • I couldn't measure line coverage locally because no Xdebug/PCOV is installed, so CI's --coverage --exactly=100.0 is the check. Every new branch has a test.

Media

No screenshots or videos: nothing in the UI changes. This only changes when the background job retries a fetch and when it gives up. A link card looks the same as before; it's just no longer lost after a temporary outage.

Limitations

  • The queue worker now reports transient HTTP failures as exceptions on each attempt, and the final failure lands in failed_jobs. This matches SyncGitHubSshKeysJob. Before, they were swallowed silently.
  • A DNS lookup that returns nothing still counts as "non-public" and is permanent, as specified.

@brendt
brendt merged commit b7e8f80 into dev-null-sh:production Oct 16, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants