Skip to content

feat(webhooks): add conditional delete precondition support - #15450

Open
hardikkaurani wants to merge 1 commit into
appwrite:mainfrom
hardikkaurani:feat-14354-conditional-webhook-delete
Open

hardikkaurani wants to merge 1 commit into
appwrite:mainfrom
hardikkaurani:feat-14354-conditional-webhook-delete

Conversation

@hardikkaurani

@hardikkaurani hardikkaurani commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Adds conditional precondition support to webhook mutations using Appwrite's existing X-Appwrite-Timestamp header (requestTimestamp) so concurrent updates or deletes cannot silently overwrite or drop each other.

Summary

  • Inject requestTimestamp and wrap deleteDocument / updateDocument with $dbForPlatform->withRequestTimestamp($requestTimestamp, ...) in:
    • Webhooks/Delete.php
    • Webhooks/Update.php
    • Webhooks/Secret/Update.php
  • Catch Utopia\Database\Exception\Conflict and throw Exception::WEBHOOK_UPDATE_CONFLICT (webhook_update_conflict, HTTP 409), matching document_update_conflict and row_update_conflict.
  • Drop the custom ifUpdatedAt parameter, X-Appwrite-If-Updated-At header, WEBHOOK_PRECONDITION_FAILED, and WebhookConditionalDeleteTest.
  • Add E2E coverage in tests/e2e/Services/Webhooks/WebhooksBase.php (testWebhookRequestTimestampPreconditions) covering stale (409 webhook_update_conflict) and matching (200 / 204) X-Appwrite-Timestamp preconditions across PUT, PATCH /secret, and DELETE.

Verification

  • php -l passed on all 6 modified files (errors.php, Exception.php, Delete.php, Update.php, Secret/Update.php, WebhooksBase.php).
  • Full E2E suite will run in GitHub Actions CI.

Resolves #14354

Copilot AI balanced review requested due to automatic review settings November 10, 2026 07:39

Copilot AI left a comment

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@hardikkaurani

hardikkaurani commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor Author

Hey @eldadfux @HarshMN2345, put this together for #14354 to add optional ifUpdatedAt / X-Appwrite-If-Updated-At precondition checks on webhook deletion. WebhookConditionalDeleteTest and Pint pass locally.

@appwrite

appwrite Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Code review

Commit Status Tier Verdict Details
5d95667 Reviewed Reviewed 🟢 S · Ready to merge 💬 Commented View review

The timestamp precondition is delegated to the database's atomic update/delete operations, and the E2E test covers stale and matching requests.

Webhook DELETE now honors X-Appwrite-Timestamp as an atomic precondition, and webhook PUT and secret updates use the same precondition behavior. A dedicated conflict error and E2E coverage exercise matching and stale timestamps across these operations.

Note

@hardikkaurani does not have write access to this repository, so Hansi does not approve automatically. A maintainer can review and approve.

Walkthrough (6)
File Change
app/config/errors.php Registers the webhook update conflict response as HTTP 409.
src/Appwrite/Extend/Exception.php Adds the webhook update conflict error identifier.
src/Appwrite/Platform/Modules/Webhooks/Http/Webhooks/Delete.php Applies the request timestamp to webhook deletion and maps database conflicts to the webhook error.
src/Appwrite/Platform/Modules/Webhooks/Http/Webhooks/Secret/Update.php Applies the request timestamp to webhook secret updates and maps conflicts.
src/Appwrite/Platform/Modules/Webhooks/Http/Webhooks/Update.php Applies the request timestamp to webhook updates and maps conflicts.
tests/e2e/Services/Webhooks/WebhooksBase.php Covers stale and current timestamp preconditions for webhook update, secret update, and deletion.

Reviewed 5d95667

Tip

Comment @appwrite review to re-run, or mention @appwrite with a question.

@appwrite appwrite Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Tier A · See the inline comments. Summary

@hardikkaurani

hardikkaurani commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor Author

Updated after the review feedback: rewrote WebhookConditionalDeleteTest to call Delete::action directly, switched header lookup in Delete.php to getHeaderLine(), and added E2E precondition tests in WebhooksBase. Unit tests and Pint pass locally. cc @eldadfux @HarshMN2345

@appwrite appwrite Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Tier S · Looks good to merge. Summary

@hardikkaurani

Copy link
Copy Markdown
Contributor Author

@HarshMN2345 Please review !

@ChiragAgg5k

Copy link
Copy Markdown
Member

Thanks for picking this up. I've updated #14354: Appwrite already has a precondition for this, X-Appwrite-Timestamp, so webhooks should reuse it instead of adding a new header and param.

Changes needed:

  1. Race: the $webhook->getUpdatedAt() !== $precondition check runs between findOne and deleteDocument, so a PUT can still land in between and get deleted. Database::deleteDocument already does this check atomically (locked read in a transaction) when a request timestamp is set. Inject requestTimestamp and wrap the delete like Databases/Collections/Documents/Delete.php does:
try {
    $dbForPlatform->withRequestTimestamp($requestTimestamp, fn () => $authorization->skip(
        fn () => $dbForPlatform->deleteDocument('webhooks', $webhook->getId())
    ));
} catch (ConflictException) {
    throw new Exception(Exception::WEBHOOK_UPDATE_CONFLICT);
}
  1. API surface: drop the ifUpdatedAt param, the x-appwrite-if-updated-at header and WEBHOOK_PRECONDITION_FAILED. Add WEBHOOK_UPDATE_CONFLICT (webhook_update_conflict, 409), matching document_update_conflict and row_update_conflict.
  2. Comparison: the string comparison would reject an equal timestamp written in another format (Z vs +00:00). Using the library check above removes it.
  3. Update: apply the same wrapper to updateDocument in Webhooks/Update.php and Webhooks/Secret/Update.php, so concurrent PUTs can't overwrite each other.
  4. Tests: remove tests/unit/Webhooks/WebhookConditionalDeleteTest.php and keep the coverage in WebhooksBase.php: delete with the current $updatedAt returns 204; delete after an intervening update returns 409 and the webhook still exists.

@hardikkaurani

Copy link
Copy Markdown
Contributor Author

@ChiragAgg5k Thanks for the detailed review and for updating #14354. I've rebased onto main and updated the PR to address every point:

  • Replaced the custom ifUpdatedAt param / x-appwrite-if-updated-at header / WEBHOOK_PRECONDITION_FAILED with requestTimestamp (X-Appwrite-Timestamp) and WEBHOOK_UPDATE_CONFLICT (webhook_update_conflict, 409) in Exception.php and app/config/errors.php.
  • Wrapped deleteDocument in Webhooks/Delete.php and updateDocument in Webhooks/Update.php and Webhooks/Secret/Update.php with $dbForPlatform->withRequestTimestamp($requestTimestamp, ...), catching ConflictException and throwing Exception::WEBHOOK_UPDATE_CONFLICT.
  • Removed tests/unit/Webhooks/WebhookConditionalDeleteTest.php and updated tests/e2e/Services/Webhooks/WebhooksBase.php (testWebhookRequestTimestampPreconditions) to verify 409 webhook_update_conflict on stale timestamps (preserving the webhook) and 200/204 on matching timestamps across PUT, PATCH /secret, and DELETE.

This branch has not been deployed

No deployments
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.

Honour X-Appwrite-Timestamp on webhook delete and update

3 participants