Skip to content

fix: serialize response models to match the published spec - #14158

Merged
ChiragAgg5k merged 2 commits into
mainfrom
fix/response-model-sdk-contracts
Oct 6, 2026
Merged

ChiragAgg5k merged 2 commits into
mainfrom
fix/response-model-sdk-contracts

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented Oct 6, 2026 •

Copy link
Copy Markdown
Member

Summary

The Appwrite MCP server uses the generated Console Python SDK, whose strict pydantic models are built from the OpenAPI spec. Sentry shows several responses that don't match the spec, so the SDK rejects them. This PR updates the response models so their output matches what the spec declares.

Issue Cause Fix
MCP-K: proxy rule deploymentResourceType fails enum validation api/redirect rules store deploymentResourceType = '', but the spec declares a nullable enum (function, site) Rule::filter() emits null instead of ''. The rule is already required => false, so the spec marks it nullable
MCP-1B: execution header value is not a string Execution::filter() only joined list values, so scalars such as content-length: 8807 passed through as int Every request/response header value is cast to string: lists are joined with , , scalars are stringified, strings are kept
MCP-1X: presence metadata is [] Empty metadata JSON-encodes as an array, but the spec declares an object Presence::filter() outputs stdClass for empty metadata, so it encodes as {}
MCP-1H / MCP-1Q: migration options / statusCounters are [] Model defaults were [], and the filter had no empty-object handling (it also returns early when there are no errors) Defaults are now stdClass, and Migration::filter() converts empty arrays to stdClass before the early return
Same pattern: schedule data is [] Schedules created without data hit the [] default, and stored {} decodes to [] Default and example are now stdClass, and Schedule::filter() converts empty arrays

I left other rule fields such as deploymentId and deploymentResourceId alone. They are required strings, so '' is valid. Migration resourceData is a JSON array in the spec, so [] is correct there. Response.php is unchanged.

Verification

  • vendor/bin/phpunit tests/unit/Utopia tests/unit/SDK: OK (361 tests)
  • Regression test ExecutionTest::testHeaderValuesAreStrings fails without the src/ change and passes with it.
  • composer lint: passed
  • composer analyze: no errors
  • composer refactor:check: OK

Related: appwrite-labs/cloud#5938

Strict SDK clients generated from the OpenAPI spec reject proxy rules with an empty deploymentResourceType, execution headers with non-string values, and empty JSON objects that encode as [] (presence metadata, migration statusCounters/options, schedule data).
@ChiragAgg5k ChiragAgg5k self-assigned this Oct 6, 2026
@ghost

ghost commented Oct 6, 2026

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The changes fit the response serialization pipeline, and no concrete defects were found in the affected models or their callers.

Normalizes response serialization to match the published model contracts: nullable deployment resource types, string-valued execution headers, and empty JSON objects for presence metadata, migration counters/options, and schedule data. Adds regression tests for normalization, defaults, and preservation of populated values.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 10
File Change
src/Appwrite/Utopia/Response/Model/Execution.php Stringifies scalar header values and joins multi-value headers.
src/Appwrite/Utopia/Response/Model/Migration.php Defaults and normalizes empty counters and options to JSON objects.
src/Appwrite/Utopia/Response/Model/Presence.php Serializes empty metadata as an object while preserving null metadata.
src/Appwrite/Utopia/Response/Model/Rule.php Normalizes an empty deployment resource type to null.
src/Appwrite/Utopia/Response/Model/Schedule.php Defaults and normalizes empty schedule data to an object.
tests/unit/Utopia/Response/Model/ExecutionTest.php Adds coverage for numeric, boolean, and multi-value header serialization.
tests/unit/Utopia/Response/Model/MigrationTest.php Covers empty and missing objects, populated values, and error sanitization.
tests/unit/Utopia/Response/Model/PresenceTest.php Covers empty, populated, and missing metadata.
tests/unit/Utopia/Response/Model/RuleTest.php Covers empty and populated deployment resource types and optionality.
tests/unit/Utopia/Response/Model/ScheduleTest.php Covers empty, missing, and populated schedule data.

Reviewed c3e44bd · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@ghost ghost 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

@github-actions

github-actions Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/response-model-sdk-contracts (after).

Metric Before After Change
🚀 Requests/sec 205.01 204.17 ⚪ -0.4%
⏱️ Latency P50 84.81 ms 85.62 ms ⚪ +1%
⏱️ Latency P95 197.57 ms 196 ms ⚪ -0.8%
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 85.62 196 12,597 204.17 -1.57
Account 165.7 293.98 663 11.07 -3.37
TablesDB 83.47 157.48 6,851 112.55 +6.63
Storage 77.01 162.27 3,315 56.77 -13.04
Functions 124.43 235.95 1,768 30.99 +0.56

Top API waits (after)

API request Max wait (ms)
tablesdb.rows.increment 439.28
functions.delete 412.59
account.name.update 402.2
account.prefs.update 372.41
functions.variables.update 354.68

@ChiragAgg5k
ChiragAgg5k merged commit bb544b0 into main Oct 6, 2026
50 checks passed
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