Skip to content

fix(certificates): skip project events for rules without a projectId - #13709

Merged
ChiragAgg5k merged 2 commits into
mainfrom
fix/certificates-rule-without-project
Sep 15, 2026
Merged

ChiragAgg5k merged 2 commits into
mainfrom
fix/certificates-rule-without-project

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented Sep 15, 2026 •

Copy link
Copy Markdown
Member

Summary

Fixes CLOUD-3R0T: Database::getDocument(): Argument #2 ($id) must be of type string, null given in the certificates worker, 13 distinct customer domains over the last week.

After domain verification the worker updates the rule, then loads the rule's project to emit webhook, function and realtime events. Every code path that creates a rule sets projectId and the schema marks it required, so the null values come from legacy rows. By the time it throws the rule update has already been written, so only the events step fails and the queue retries it uselessly.

A rule with no project is now treated like the existing console exemption: the update is written and broadcast on the bus, and the per-project events are skipped.

Testing

Pint passes. No test added; a rule without a projectId can't be created over HTTP, so the state isn't reachable from an E2E test.

Legacy rules exist with a null projectId. The rule update was already written when the project lookup threw a TypeError, so only the events step failed and the queue retried it uselessly (CLOUD-3R0T).
@greptile-apps

greptile-apps Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

The PR appears safe to merge; the null project lookup is prevented and the previous implementation-coupled test finding is fully resolved.

Fix All in Claude CodeFindings

  1. P2 Test Mirrors Worker Internals ▶
Fix with agent prompt
### Issue 1
tests/unit/Platform/Workers/CertificatesTest.php:59-66
This test exposes and calls the protected `updateRuleAndSendEvents()` helper, while the related mock expectations prescribe exact database and publisher calls. This violates the repository directive to test observable behavior rather than mirror source internals: a harmless refactor of the helper or event dispatch mechanism would fail the test even if persistence and externally visible behavior remained correct. The repository requirement must be satisfied before merging; exercise the public worker flow and assert durable state and captured event outputs 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

The PR prevents legacy certificate rules with a missing projectId from causing a null project lookup after their status is updated.

  • Normalizes a missing project identifier to an empty string.
  • Skips project-scoped function, webhook, and realtime events when no project is associated with the rule.
  • Retains the local RuleUpdated bus dispatch.
  • Removes the implementation-coupled unit test identified in the previous review.

Reviews (2) · Last reviewed commit: "test: drop certificates worker unit test"

Comment on lines +59 to +66
$worker = new class () extends Certificates {
public function update(Document $rule, Database $dbForPlatform, Event $queueForEvents, Webhook $queueForWebhooks, FunctionPublisher $publisherForFunctions, Realtime $queueForRealtime, Bus $bus): void
{
$this->updateRuleAndSendEvents($rule, $dbForPlatform, $queueForEvents, $queueForWebhooks, $publisherForFunctions, $queueForRealtime, $bus);
}
};

$worker->update($rule, $dbForPlatform, $queueForEvents, $queueForWebhooks, $publisherForFunctions, $queueForRealtime, $bus);

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 Test Mirrors Worker Internals

This test exposes and calls the protected updateRuleAndSendEvents() helper, while the related mock expectations prescribe exact database and publisher calls. This violates the repository directive to test observable behavior rather than mirror source internals: a harmless refactor of the helper or event dispatch mechanism would fail the test even if persistence and externally visible behavior remained correct. The repository requirement must be satisfied before merging; exercise the public worker flow and assert durable state and captured event outputs 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/Workers/CertificatesTest.php
Line: 59-66

Comment:
**Test Mirrors Worker Internals**

This test exposes and calls the protected `updateRuleAndSendEvents()` helper, while the related mock expectations prescribe exact database and publisher calls. This violates the repository directive to test observable behavior rather than mirror source internals: a harmless refactor of the helper or event dispatch mechanism would fail the test even if persistence and externally visible behavior remained correct. The repository requirement must be satisfied before merging; exercise the public worker flow and assert durable state and captured event outputs 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

@github-actions

github-actions Bot commented Sep 15, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/certificates-rule-without-project (after).

Metric Before After Change
🚀 Requests/sec 441.22 432.23 ⚪ -2%
⏱️ Latency P50 39.36 ms 40.33 ms ⚪ +2.5%
⏱️ Latency P95 92.61 ms 94.55 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 40.33 94.55 26,391 432.23 +1.93
Account 70.11 134.59 1,389 23.12 -8.55
TablesDB 38.42 74.18 14,353 237.15 +0.51
Storage 37.39 91.42 6,945 116.89 +5.04
Functions 57.31 114.77 3,704 63.17 +3.32

Top API waits (after)

API request Max wait (ms)
account.name.update 234.52
tablesdb.rows.create 220.11
functions.variables.update 199.93
storage.files.preview 194.28
functions.create 190

@ChiragAgg5k
ChiragAgg5k merged commit 7670364 into main Sep 15, 2026
47 checks passed
@ChiragAgg5k
ChiragAgg5k deleted the fix/certificates-rule-without-project branch September 15, 2026 15:40
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