Skip to content

fix(certificates): keep retrying DNS verification for rules older than 3 days - #13539

Closed
HarshMN2345 wants to merge 2 commits into
mainfrom
claude/domain-verification-retry-window
Closed

HarshMN2345 wants to merge 2 commits into
mainfrom
claude/domain-verification-retry-window

Conversation

@HarshMN2345

@HarshMN2345 HarshMN2345 commented Sep 8, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

A custom domain rule stays in created status until its DNS verification succeeds. Interval::verifyDomain() retries those rules every 2 minutes, but only the ones created in the last 3 days:

$fromTime = new DateTime('-3 days'); // Max 3 days old

$rules = $dbForPlatform->find('rules', [
    Query::createdAfter(DatabaseDateTime::format($fromTime)),
    Query::equal('status', [RULE_STATUS_CREATED]),
    ...

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:

  1. Rule is created, verifyRule() fails because DNS is not pointed yet, status stays created. No certificate job is queued, so the domain is never attached to the CDN.
  2. The interval task re-checks it for three days, then stops.
  3. The user points the CNAME on day 5. Traffic now reaches the CDN, which has never heard of the domain, and gets an error page — permanently, until someone retries verification by hand.

This drops the age bound. Nothing else about the scan changes: it is still capped at limit(100) per tick and ordered by $updatedAt ascending, and Certificates::handleDomainVerificationAction() writes the rule back on every attempt (status on success, logs on failure) via updateRuleAndSendEvents(). So each attempt moves that rule to the back of the queue and the sweep round-robins fairly however many rules are waiting.

The $time variable removed alongside it was already dead — assigned and never read.

Test Plan

tests/unit/Platform/Tasks/IntervalTest.php drives the domainVerification task through a Database stub that captures the queries, and asserts:

  • no query filters on $createdAt — this is the regression, and it fails on main
  • orderAsc('$updatedAt') and limit(100) are still there, since they are what keeps the now-unbounded scan fair and bounded per tick
$ vendor/bin/phpunit tests/unit/Platform/Tasks/IntervalTest.php
OK, Tests: 2, Assertions: 8

$ composer lint src/Appwrite/Platform/Tasks/Interval.php tests/unit/Platform/Tasks/IntervalTest.php
{"tool":"pint","result":"passed"}

Verified against main by stashing the Interval.php change: testDomainVerificationRetriesRulesOfAnyAge fails, 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 touch verifyDomain().

They do both edit src/Appwrite/Platform/Tasks/Interval.php, and whichever lands second needs a manual check. This PR deletes use DateTime; and use Utopia\Database\DateTime as DatabaseDateTime; because verifyDomain() was their only consumer. #13467 adds generateCertificate(), which uses both. The deletions do not overlap any #13467 hunk, so git will merge them silently and generateCertificate() will hit an undefined-class fatal. Whoever merges second should restore the two imports.

Checklist

  • Have you read the Contributing Guidelines on issues?
  • If the PR includes a change to an API's metadata (desc, label, params, etc.), does it also include updated API specs and example docs? — no API metadata changed.

🤖 Generated with Claude Code

https://claude.ai/code/session_01MeytoiisEusFMCU44PDYav

…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
@greptile-apps

greptile-apps Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

The runtime change appears sound, but the explicit repository testing requirement must be satisfied before merging.

Fix All in Claude CodeFindings

  1. P2 Tests Mirror Implementation Details ▶
Fix with agent prompt
### Issue 1
tests/unit/Platform/Tasks/IntervalTest.php:15-35
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.

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

This PR removes the three-day creation-age filter from periodic domain verification, allowing rules that remain in the created state to continue receiving verification attempts.

  • Removes the obsolete date calculations and imports.
  • Preserves the region, status, update-order, and batch-limit query constraints.
  • Adds unit tests that inspect the constructed database queries, although those tests violate the repository requirement to test observable behavior.

Reviews (2) · Last reviewed commit: "Merge main into domain-verification-retr..."

@github-actions

github-actions Bot commented Sep 8, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → claude/domain-verification-retry-window (after).

Metric Before After Change
🚀 Requests/sec 483.66 494.04 ⚪ +2.1%
⏱️ Latency P50 36 ms 35.13 ms ⚪ -2.4%
⏱️ Latency P95 84.28 ms 82.51 ms ⚪ -2.1%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 35.13 82.51 30,267 494.04 -1.77
Account 62.04 116.12 1,593 26.55 -7.85
TablesDB 33.44 64.99 16,461 271.41 -2.28
Storage 32.73 78.04 7,965 132.88 -2
Functions 50.81 100.3 4,248 71.49 -1.72

Top API waits (after)

API request Max wait (ms)
functions.create 258.85
functions.variables.update 212.15
account.name.update 203.85
tablesdb.rows.create 171.47
storage.buckets.create 164.27

Comment on lines +15 to +35
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());
}

/**

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 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!

Fix in Claude Code Fix in Codex

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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

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.

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.

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