Skip to content

fix(cdn): retry a failed Fastly TLS subscription with force - #304

Merged
Meldiron merged 1 commit into
mainfrom
fix/cdn-fastly-retry-with-force
Sep 21, 2026
Merged

Meldiron merged 1 commit into
mainfrom
fix/cdn-fastly-retry-with-force

Conversation

@Meldiron

Copy link
Copy Markdown
Contributor

Problem

Seen in production on a custom domain's certificate logs:

Failed to retry Fastly TLS subscription with status 400: Subscription has active domains

A subscription reaches failed when a Fastly-side renewal does not complete, typically because the domain's DNS no longer reaches Fastly or a CAA record now excludes the CA. The certificate issued earlier is still deployed and serving, which Fastly calls an active domain. Fastly refuses to edit a subscription with active domains unless the request carries force=true; its docs describe force as what lets you "edit and delete a subscription with active domains". FastlyTls::retrySubscription sent the PATCH state=retry without it, so once a renewal had failed the subscription could never be retried through this adapter. Every consumer attempt, maintenance renewals and re-verify alike, hit the same 400.

Change

The retry PATCH goes to /tls/subscriptions/{id}?force=true, matching what deleteCertificate already does. Fastly's warning about force concerns removing an active domain from a subscription; a retry keeps the domain and only asks for issuance again, so the deployed certificate keeps serving while the retry runs. Nothing else changes.

What this does not fix

The retry succeeds only if whatever made the renewal fail is gone. If the DNS or CAA problem is still there, Fastly fails the retry again, and with #300 the rule's logs will carry Fastly's own reason and the challenge to fix it.

Tests

FastlyTlsTest.php: the existing retry test now asserts the URL carries force=true and the body asks for retry; a new test scripts Fastly's 400 and asserts the exception carries Fastly's message and that nothing further is attempted.

bin/monorepo check cdn passes (Pint, PHPStan, Rector). Tests were not run locally.

Independent of #300 and #303; touches only FastlyTls.

🤖 Generated with Claude Code

A subscription fails on a renewal while the certificate it issued earlier is
still deployed, which Fastly calls an active domain, and Fastly refuses to
edit such a subscription without force. The retry was sent without it and
came back 400 "Subscription has active domains", so a domain whose renewal
had failed once could never be retried. A retry keeps the domain and only
asks for issuance again, so the deployed certificate keeps serving while
the retry runs.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@greptile-apps

greptile-apps Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

The production fix appears correct, but the repository's explicit testing requirement must be satisfied before merging.

Fix All in Claude CodeFindings

  1. P2 Tests mirror request construction ▶
Fix with agent prompt
### Issue 1
packages/cdn/tests/Cdn/Certificates/Provider/FastlyTlsTest.php:107-109
These assertions copy the exact HTTP method, configured API base, query string, and nested `state=retry` value from the implementation. The related exact call-count assertion also pins the current request sequence. This violates the repository directive to test observable behavior rather than mirror source code or configuration. Make the fake client accept the retry only when `force=true` is present, then assert the resulting provider behavior. This repository requirement must be satisfied before merging.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

The PR adds Fastly's force=true query parameter when retrying failed TLS subscriptions and extends the provider tests.

  • Failed subscriptions are still the only state routed through the retry operation.
  • Fastly rejection details continue to propagate through the provider exception.
  • The production change is narrowly scoped, but the new request-shape assertions violate the repository's testing policy.

Reviews (1) · Last reviewed commit: "fix(cdn): retry a failed Fastly TLS subs..."

Comment on lines 107 to +109
$this->assertSame('PATCH', $client->calls[1]['method']);
$this->assertSame('https://api.fastly.com/tls/subscriptions/sub_123?force=true', $client->calls[1]['url']);
$this->assertSame('retry', $client->calls[1]['body']['data']['attributes']['state']);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Tests mirror request construction

These assertions copy the exact HTTP method, configured API base, query string, and nested state=retry value from the implementation. The related exact call-count assertion also pins the current request sequence. This violates the repository directive to test observable behavior rather than mirror source code or configuration. Make the fake client accept the retry only when force=true is present, then assert the resulting provider behavior. This repository requirement must be satisfied before merging.

Context Used: Call out and harshly judge implementation-coupled tests. We don't mirror source code, configuration, or version pins in assertions. We test observable behavior; use linters for syntax and schema checks. (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/cdn/tests/Cdn/Certificates/Provider/FastlyTlsTest.php
Line: 107-109

Comment:
**Tests mirror request construction**

These assertions copy the exact HTTP method, configured API base, query string, and nested `state=retry` value from the implementation. The related exact call-count assertion also pins the current request sequence. This violates the repository directive to test observable behavior rather than mirror source code or configuration. Make the fake client accept the retry only when `force=true` is present, then assert the resulting provider behavior. This repository requirement must be satisfied before merging.

**Context Used:** Call out and harshly judge implementation-coupled tests. We don't mirror source code, configuration, or version pins in assertions. We test observable behavior; use linters for syntax and schema checks. ([source](https://app.greptile.com/review/custom-context?memory=instruction-0))

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Fix in Claude Code Fix in Codex

@Meldiron
Meldiron merged commit 5040e5d into main Sep 21, 2026
6 checks passed
Meldiron added a commit that referenced this pull request Sep 21, 2026
Drops the parts of this branch that #300 and #304 already landed on main,
and keeps only what is still unique to it.

Superseded, now taken from main:
- `Exception\Certificate`: main's carries `Challenge` objects, `getWarnings()`
  and `isBlocked()` where this branch had a raw `getDnsRecords()` array.
- `Status::BLOCKED` and the `Provider::getCertificateStatus()` `@throws`.
- `FastlyTls::getCertificateStatus()` blocked-authorization reporting, the
  `tls_authorizations` include, and the ~210 lines of tests covering them.
- The README paragraph describing the old `getDnsRecords()` shape.

Kept from this branch:
- `Fastly`: unlinked and classic-route domain ownership, `fqdn_match=exact`
  with a truncation guard, and `stdClass` response handling.
- `FastlyTls`: the exclusive-ownership check before a `force=true` delete,
  and the `findSubscription()` hardening.

`Fastly::issueCertificate()` now uses main's `catch (Certificate)` around
`getCertificateStatus()` on the reassignment path, since that call throws
on a blocked authorization rather than returning a status.

`bin/monorepo check cdn` passes; 204 CDN tests pass.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
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.

1 participant