Repository navigation
fix(certificates): requeue certificates still being generated - #14009
Conversation
Identical apex CAA records made Certainly refuse issuance, and an issued Fastly certificate could be left off the TLS configuration so the edge kept serving the shared default cert. Collapse duplicate CAA when a zone is built, create the missing activation before a custom domain can be verified, and recheck rules that are still generating. Co-authored-by: Harsh Mahajan <[email protected]>
…rating The interval follow-up only needs to see whether issuance and TLS activation finished. Running DNS verification again can mark the domain unverified on a transient lookup. Co-authored-by: Harsh Mahajan <[email protected]>
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
🟢 Tier S · Ready to mergeThe PR adds interval polling for certificates still generating after five minutes and skips repeated DNS validation on those follow-up jobs. The certificate worker checks delayed-provider readiness and keeps provider-stage failures retryable up to five attempts, notifying the security address when attempts are exhausted. Latest changes: The newest commits inline the worker readiness helpers, mark already-valid instant certificates verified, simplify comments, and namespace certificate-generation span attributes.
📂 Walkthrough · 3
Reviewed the commits since |
|
| ]); | ||
|
|
||
| $scanned = \count($rules); | ||
| Span::add('interval.certificate_generation.scanned', $scanned); |
There was a problem hiding this comment.
Span keys violate naming guide The new
interval.certificate_generation.scanned key uses dots to separate the task and metric; the new processed and failed keys follow the same pattern. The repository guide requires snake_case span keys and reserves dots for child relationships. Rename these keys consistently before merging.
Context Used: AGENTS.md (source)
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/Appwrite/Platform/Tasks/Interval.php
Line: 169
Comment:
**Span keys violate naming guide** The new `interval.certificate_generation.scanned` key uses dots to separate the task and metric; the new `processed` and `failed` keys follow the same pattern. The repository guide requires snake_case span keys and reserves dots for child relationships. Rename these keys consistently before merging.
**Context Used:** AGENTS.md ([source](https://github.com/appwrite/appwrite/blob/main/AGENTS.md))
---
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!
There was a problem hiding this comment.
Keeping these. They mirror the sibling task in the same file on main, interval.domain_verification.{scanned,processed,failed}: the task is the parent and each count is its child, in snake_case. Bare scanned/processed would be ambiguous next to that sibling.
Generated by Claude Code
0b92e48 to
be14de4
Compare
Nine review threads, and one of them was a real hole in the fix itself. Activation failure was a dead end. A failure set the rule to RULE_STATUS_CERTIFICATE_GENERATION_FAILED, which is 'unverified' -- but the worker's own guard accepts only generating or verified, and the new interval requeues only generating. So the one path this PR exists to recover from left the rule somewhere nothing would ever pick it up again. It now stays on generating while the only outstanding work is the provider's, bounded by MAX_GENERATION_ATTEMPTS, and the security mail fires on the terminal attempt instead of once per retry. An issued subscription with no certificate on it yet no longer throws. Fastly reports issued slightly before the certificate appears, and throwing there turned a normal intermediate state into a failure. getCertificateStatus() reports PROCESSING instead, so the caller comes back. A 409 from /tls/activations is no longer assumed to be our own activation. The conflict can be another certificate holding the hostname, which would have reported the domain ready while the edge served someone else's certificate. The provider re-checks and throws when ours is not the one attached. PHPStan: the new helpers read everything through explicit is_array/is_string narrowing, so they add no offset-on-mixed errors and the baselined counts in packages/cdn are untouched (verified pattern by pattern against the base). extractRenewDate keeps its own extraction for that reason -- sharing the new helper would have removed a baselined access and broken the count the other way. Interval: $updatedAt is only written when a job finishes, so a 60-second threshold could enqueue a hostname whose previous attempt was still running. Raised to 5 minutes, which is past any provider's job and still inside what a waiting customer notices. Span keys are now scanned/processed/failed -- Span::init() already names the span, so the old keys were both dot-separated against the convention and redundant with it. The CAA collapse is now a general duplicate collapse. An RRset is a set for every type, not just CAA, and the justification no longer rests on Fastly treating two identical CAA records as a conflict -- which I could not substantiate and have retracted on appwrite-labs/cloud#6228. It keys on everything that distinguishes a record, so MX and SRV differing only in priority, weight or port both survive. Tests: FastlyTlsTest no longer asserts exact URLs or indexes into the call list; it asks which hostnames were activated and with which certificate. Added the 409-with-another-certificate case and two Zone cases covering the generalisation. Verified locally: packages/dns 79 pass, packages/cdn 100 pass, the worker cases 6 pass, and the new bound was seen red by raising it. Pint clean.
|
All nine threads addressed in 631bcac. Seven fixed, two I'm standing down on with reasons. One of the findings was a real hole in the fix itself, so starting there. The activation failure path was a dead end
It now stays on Covered by two cases: the first failure leaves the rule retryable with Pending issuance losing follow-upRelated, and fixed by the same change plus one more: an issued subscription that carries no certificate yet no longer throws. Fastly reports A 409 no longer counts as our activationRight, and this one could have served the wrong certificate silently. A conflict can be another certificate already holding the hostname — accepting it would report the domain ready while the edge terminates TLS with someone else's cert. The provider now re-checks after a 409 and throws when ours is not the one attached. New case covers the conflict-with-another-certificate branch. PHPStanFixed without touching the baseline. Every read in the new helpers goes through explicit Worth noting deliberately: Interval requeueValid. Span keysFixed, and the finding was righter than it looked: Tests mirroring the request flowFixed. No test indexes into The CAA collapse is now a general duplicate collapseThis one needs a correction rather than a defence. The description claimed Fastly's CA treats two identical CAA records as a conflict and stops issuance. I could not substantiate that and have retracted it. The zone served only So the collapse is re-justified on what is actually true: an RRset is a set for every type, and RFC 2181 §5 makes publishing the same record twice invalid rather than merely redundant. It now keys on everything that distinguishes a record, so MX and SRV differing only in priority, weight or port both survive — two new I'd still rather this half were judged on that basis than on the Fastly claim. Standing down: worker tests in the unit tierBoth of you flagged
If the tier matters more than the coverage, say so and I'll delete them rather than fake an e2e that doesn't exercise the path. Verified locally
Generated by Claude Code |
Packages / cdn failed on both, and my previous commit's claim that the baseline
was untouched was only true of src. phpstan.neon is level max over src AND
tests, which I had not accounted for.
Rector: ArrayFirstLastRector wants array_last($ids), not
$ids[array_key_last($ids)]. PHP is 8.5, so array_last() exists.
PHPStan, 26 errors, all in FastlyTlsTest.php, from two separate causes:
The helpers I added read $call['body']['data'][...] -- a chained access on a
mixed receiver -- and declared list<string> while returning list<mixed>. They are
now one activations() returning list<array{domain: string, certificate: string}>,
narrowing before each descent. TestClient types $calls as
array{url:string,method:string,body:mixed}, so only body needs a guard; guarding
url or method would itself trip the always-true check.
The rest was already broken before my commit. The fixture builders mutated
$body['data'][0]['relationships']['tls_certificates'] and appended to
$body['included'], both chained writes on mixed, and both un-baselined. Giving
subscription() a $certificates parameter and issuedSubscription() an
$alsoCertificates parameter removes the mutation entirely, so the tests build
their fixtures instead of patching them.
Every baselined pattern in the test file now matches the pre-PR count exactly
('data' 6, 'id' 3, 'relationships' 4, offset 0 3, 'tls_domain' 1), which is what
the counts were generated from.
The last error was one I would have shipped: subscription()'s new $certificates
parameter had no @PARAM, and missingType.iterableValue fires from level 6 up with
no baseline entry in this package. I had annotated issuedSubscription()'s new
parameters and missed this one. Swept the diff -- every array parameter in the
four changed files is now docblock-typed.
cdn 100 pass, dns 79 pass, worker 6 pass, Pint clean. PHPStan still cannot run
here, so this round was audited by five independent reviewers instead; the
missing @PARAM is what they found, and they confirmed the offsetAccess counts
reconcile.
Review caught an asymmetry I introduced. I made ensureActivated() return false when the subscription carries no certificate to attach, honoured it in the issued branch, and discarded it in the renewing branch. My reasoning for discarding it was wrong: I assumed a renewing subscription without a new certificate is normal because the old one still serves. But issuedCertificateId() returns null only when there are NO certificate references at all, which means there is no old certificate either. Nothing is attached and nothing can be attached, and the worker's isReady() counts renewing as ready -- so that state would have marked the domain verified while the edge served the default certificate. The same bug the issued branch was fixed for. Both branches now return PROCESSING, and the docblock says why both have to. Two tests, the first seen red against the reverted guard: a renewing subscription with no certificate reports PROCESSING and activates nothing, and one that does carry a certificate still reports RENEWING and gets attached -- so the guard cannot swallow the normal path. cdn 102 pass, Pint clean.
|
Why it isn't this PR'sThe decisive point is the delta. Teams was green at Supporting, all checked rather than assumed:
No fix exists to port. This isn't a known breakage with a landed fix, so there is nothing to bring into this PR, and I'm not widening it on a guess. Why I can't name the assertion — and the fix for thatAt this commit, the So the failure is structurally unreadable through the API, which is worse than the failure itself: any future E2E assertion failure in this job is equally invisible. That fix already exists — commit What I'm doingRe-running the job once, which is the one re-run this warrants — if it goes green, that closes it; if it reds again, it is real and needs One lead I'll flag precisely so nobody over-reads it: the final request burst matches Generated by Claude Code |
The activation work in this PR could not run. Fastly's constructor hardcoded tlsConfigurationId: '' when building FastlyTls, ensureActivated() returns early on an empty one, and nothing could pass a value in -- this is the only place FastlyTls is constructed outside tests. So POST /tls/activations was never sent however correct the code behind it was, and an issued certificate was never attached to its hostname. The id is now a constructor parameter. Empty stays the default and still means domain management owns the hostname -- the subscription stays unpinned and no activation is created -- so nothing changes until a value is supplied. Two tests, both seen red first against the hardcode: with a configuration id an issued subscription gets a POST /tls/activations carrying that id, the certificate and the hostname; without one the status call makes no activation request at all. cdn 104 pass, Pint clean. Rector cannot run here (the local vendor's rector fatals on --version, before reading any file), so CI is the check for it.
|
Flagging a correction against myself, because it changes what this PR is worth. As written, the activation work could not run. So
One trap for whoever wires the id
if (\in_array($domainType, ['site', 'network', 'redirect'], true)) {
return [$this->networkProvider];
}and Two things this still does not settle
I'd rather say this plainly than have it found after merge. Generated by Claude Code |
…eration The Fastly TLS activation work and the zone duplicate-record cleanup move to their own pull requests, so each can be merged on its own. What stays here does not depend on either: the interval requeues rules still generating, and the worker keeps a provider-side failure retryable. The worker unit tests go back to main. AGENTS.md covers workers through e2e rather than unit tests.
- A job that finds a valid certificate on an instant provider now marks the rule verified. It used to leave it generating, which the interval task now requeues every few minutes. - A delayed provider whose order is already issued falls through to the regular issue path, so the certificate keeps the provider's renew date. It used to store the current time, which made maintenance requeue it on every cycle. - Inline the single-use helpers into the generation flow, keep main's comments where the behaviour is unchanged, and namespace the new span keys under interval.certificate_generation like the sibling task. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01MeytoiisEusFMCU44PDYav
Split out of #14009 so it can be judged on its own. When FastlyTls has a TLS configuration id, an issued or renewing subscription gets a TLS activation for every hostname on it, using the certificate that expires last. A 409 is re-checked rather than taken as success, since it can mean another certificate already holds the hostname. An issued subscription that carries no certificate yet reports processing. Fastly takes the id as a constructor parameter and forwards it; it was hardcoded empty. Empty keeps today's behaviour exactly: the subscription stays unpinned and nothing is activated.
Merges main a2cca78 (#14009, #14106, #14117, #14115, #14119, #14114, #14101, #14125, #14129, #14127) so cloud#5410 can require a train head that contains main at or after 0ed7232. Conflicts: none. Database 8.0 port: none needed. Main's new code only uses Document getAttribute/setAttribute and Query::equal/lessThan/orderAsc/limit (Tasks/Interval.php), all unchanged in database 8.0; no removed Database::* constants, config collections, or model magic reads. composer.json and composer.lock are untouched by main, so the train's database and migration pins stay as they are. Co-Authored-By: Claude Opus 5.5 <[email protected]>
What does this PR do?
A custom domain on a delayed certificate provider can stay on "Generating certificate" indefinitely. If the first issuance check runs while the provider is still issuing, nothing comes back to it:
Interval::verifyDomainonly revisits rules increated, which are still waiting on DNS.Maintenanceonly revisits certificates that have arenewDate, and a pending subscription has none.So the rule stays in
verifying, and the retry endpoint ignores rules in that status. This PR:skipDomainValidation, since DNS already passed when the rule entered that status. Five minutes because$updatedAtis written when a job finishes; a shorter window could requeue a hostname whose previous attempt is still running.unverified, which nothing retries. The security mail goes out once, on the final attempt. DNS failures stay terminal, as before.A rule the provider keeps pending without failing stays generating and is requeued each tick, capped at 100 rules per tick, until the provider settles it.
Test Plan
No new automated test. AGENTS.md covers workers and tasks through e2e, and e2e cannot reach this path: the worker there always uses Let's Encrypt, which issues synchronously, so a rule never waits on a delayed provider. The existing
CertificatesDomainValidationTestcases are unchanged and still describe the flow.Locally:
php -land Pint on the three files. PHPStan and unit tests run in CI.To verify on an environment with a delayed provider:
Related PRs and Issues
Checklist