Repository navigation
fix(certificates): keep retrying DNS verification for rules older than 3 days - #13539
HarshMN2345 wants to merge 2 commits into
Conversation
…n 3 days A custom domain rule stays in `created` status until its DNS verification succeeds. The interval task that retries those rules only looked at rules created in the last 3 days, so a domain whose CNAME is pointed later is never re-checked: the rule never reaches `certificate-generating`, no certificate job is queued, and the domain is never attached to the CDN. Traffic that reaches the CDN for a domain it has never heard of gets an error page, and it stays that way until someone retries verification by hand. Drop the age bound. The scan is still bounded by `limit(100)` per tick and ordered by `$updatedAt` ascending, and every attempt writes the rule back (status on success, logs on failure), so rules round-robin through the sweep without starving each other however many are waiting. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01MeytoiisEusFMCU44PDYav
|
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
Refreshes the base so CI runs against current main. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01MeytoiisEusFMCU44PDYav
| public function testDomainVerificationRetriesRulesOfAnyAge(): void | ||
| { | ||
| foreach ($this->domainVerificationQueries() as $query) { | ||
| $this->assertNotSame('$createdAt', $query->getAttribute(), 'A rule stuck on DNS verification must stay in the scan however old it is'); | ||
| } | ||
| } | ||
|
|
||
| public function testDomainVerificationRetriesOldestAttemptsFirst(): void | ||
| { | ||
| $queries = $this->domainVerificationQueries(); | ||
|
|
||
| $order = $this->queryOfMethod($queries, Query::TYPE_ORDER_ASC); | ||
| $this->assertInstanceOf(Query::class, $order); | ||
| $this->assertSame('$updatedAt', $order->getAttribute()); | ||
|
|
||
| $limit = $this->queryOfMethod($queries, Query::TYPE_LIMIT); | ||
| $this->assertInstanceOf(Query::class, $limit); | ||
| $this->assertSame(100, $limit->getValue()); | ||
| } | ||
|
|
||
| /** |
There was a problem hiding this comment.
Tests Mirror Implementation Details
These tests capture the private task callback's Query objects and assert exact field names, ordering, and a literal limit. That violates the repository directive to test observable behavior rather than mirror source code or configuration. Harmless query refactors will break this suite, while regressions in actual verification dispatch can still pass. This repository requirement must be satisfied before merging; test old and recent rules and verify which certificate jobs are published instead.
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: tests/unit/Platform/Tasks/IntervalTest.php
Line: 15-35
Comment:
**Tests Mirror Implementation Details**
These tests capture the private task callback's `Query` objects and assert exact field names, ordering, and a literal limit. That violates the repository directive to test observable behavior rather than mirror source code or configuration. Harmless query refactors will break this suite, while regressions in actual verification dispatch can still pass. This repository requirement must be satisfied before merging; test old and recent rules and verify which certificate jobs are published instead.
**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!
There was a problem hiding this comment.
Agreed, and AGENTS.md is stricter than this comment: "Do not unit-test HTTP route actions, CLI tasks, or workers — e2e covers those surfaces; unit-test the libraries they call." Interval is a CLI task, so this file shouldn't exist in tests/unit/ at all, independently of what it asserts.
The substantive half is also right. Asserting that no query filters on $createdAt proves the line was deleted, not that an old rule gets a verification job. A stub Database can't close that gap either — it would have to reimplement query filtering to mean anything, which is the same mirroring one level down. The behaviour is only observable against a real database: seed a rule created 5 days ago, tick the task, assert a job was published for it.
That test already has a home. #13573 adds tests/e2e/General/Certificates/IntervalTest.php, which drives the real Interval task against a throwaway PostgreSQL schema with a capturing publisher — exactly the shape this needs, using the fixture #13570 introduces.
So the fix isn't a rewrite in place; it's moving this PR's coverage onto that fixture, which makes this branch depend on the stack rather than stand beside it. That also retires the merge hazard called out in the description: this PR drops use DateTime; and use Utopia\Database\DateTime as DatabaseDateTime; because verifyDomain() was their only consumer, while #13573's generateCertificate() needs both, and the hunks don't overlap — so whichever lands second merges clean and fatals. In one lineage that conflict resolves once and can't recur.
Flagging it to the PR author rather than reordering their stack unilaterally. I'd rather not leave the disallowed unit test in place, so the production change here may end up folded into #13573 instead.
Generated by Claude Code
There was a problem hiding this comment.
Agreed. AGENTS.md makes the added test invalid on two independent grounds: it unit-tests a CLI task, and it asserts query construction instead of observable behavior. The production change is still correct, but its regression coverage belongs in the real PostgreSQL e2e IntervalTest: seed a created rule older than three days, run the task, and assert that a certificate-verification message is published. Folding the production change into the stacked certificate PR is the cleanest option and removes the import merge hazard; if the PRs remain separate, the DateTime imports must be restored when they are combined. No new persistent rule is needed—the repository guidance already captures this convention.
What does this PR do?
A custom domain rule stays in
createdstatus until its DNS verification succeeds.Interval::verifyDomain()retries those rules every 2 minutes, but only the ones created in the last 3 days:So a user who adds the domain in the console first and points the CNAME later — which is the normal order, since the console shows you the record to add — falls off the retry list after three days:
verifyRule()fails because DNS is not pointed yet, status stayscreated. No certificate job is queued, so the domain is never attached to the CDN.This drops the age bound. Nothing else about the scan changes: it is still capped at
limit(100)per tick and ordered by$updatedAtascending, andCertificates::handleDomainVerificationAction()writes the rule back on every attempt (status on success,logson failure) viaupdateRuleAndSendEvents(). So each attempt moves that rule to the back of the queue and the sweep round-robins fairly however many rules are waiting.The
$timevariable removed alongside it was already dead — assigned and never read.Test Plan
tests/unit/Platform/Tasks/IntervalTest.phpdrives thedomainVerificationtask through aDatabasestub that captures the queries, and asserts:$createdAt— this is the regression, and it fails onmainorderAsc('$updatedAt')andlimit(100)are still there, since they are what keeps the now-unbounded scan fair and bounded per tickVerified against
mainby stashing theInterval.phpchange:testDomainVerificationRetriesRulesOfAnyAgefails, then passes with it.Related PRs and Issues
Part of the domain/SSL work alongside #13467. The two fix different stages of the pipeline and neither depends on the other: this one is the DNS verification stage (
created→certificate-generating), #13467 is the issuance stage after verification already succeeded. #13467 does not touchverifyDomain().They do both edit
src/Appwrite/Platform/Tasks/Interval.php, and whichever lands second needs a manual check. This PR deletesuse DateTime;anduse Utopia\Database\DateTime as DatabaseDateTime;becauseverifyDomain()was their only consumer. #13467 addsgenerateCertificate(), which uses both. The deletions do not overlap any #13467 hunk, so git will merge them silently andgenerateCertificate()will hit an undefined-class fatal. Whoever merges second should restore the two imports.Checklist
🤖 Generated with Claude Code
https://claude.ai/code/session_01MeytoiisEusFMCU44PDYav