Probe editor capability endpoints instead of trusting the route list#22921
Draft
jkmassel wants to merge 2 commits into
Draft
Probe editor capability endpoints instead of trusting the route list#22921jkmassel wants to merge 2 commits into
jkmassel wants to merge 2 commits into
Conversation
Fixes the editor failing to launch on sites where the WP.com REST proxy advertises `wp-block-editor/v1/settings` in its route list but the actual call 404s — most visibly on JPC sandboxes like `protective-artifact-leopard.jurassic.ninja`. The old detection asked `apiRoot().get()` whether the route was registered; the route was there, capability said "supported," then the editor's settings fetch 404'd. Replace the route-advertisement check with direct endpoint probes via OkHttp: - 2xx / 401 / 403 → Supported (route exists; auth required is fine) - 404 → Unsupported - network / 5xx → Inconclusive, leave the cached pref alone Probes are cancellable (`suspendCancellableCoroutine` + `Call.cancel` via `invokeOnCancellation`) so dangling preloads don't keep sockets open after the scope is torn down. Preserves the Atomic-direct-host fix from #22879/#22883: GutenbergKit fetches `wp-block-editor/v1/settings` from the direct host on Atomic sites (bypassing `siteApiRoot`), so capability detection must too — pinned with a MUST-NOT-REMOVE test. `getSupportsEditorSettingsForSite` now prefers the probe answer when it has run, falling back to the legacy `EditorSettingsTable` row as the first-launch fast-path. Auth-header construction factored into `EditorAuthHeaderBuilder` so the probe and `GutenbergKitSettingsBuilder` cannot drift on scheme selection.
Collaborator
Generated by 🚫 Danger |
Contributor
|
|
Contributor
|
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## release/26.8 #22921 +/- ##
================================================
+ Coverage 37.34% 37.35% +0.01%
================================================
Files 2319 2320 +1
Lines 124678 124724 +46
Branches 16952 16964 +12
================================================
+ Hits 46556 46595 +39
- Misses 74361 74362 +1
- Partials 3761 3767 +6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…retry Review follow-ups on the endpoint-probe approach: - Atomic settings probe now requires an application password. The direct host doesn't honor the WP.com bearer, and we don't want to send WP.com credentials to whatever host `wpApiRestUrl` points at. Atomic sites that haven't minted an app password yet (e.g. before the headless mint completes) return Inconclusive and leave the cached pref alone until the next preload. - Each probe attempt is bounded by a 5s timeout (instead of inheriting the REGULAR client's 60s read timeout) and retried once on a transport-level Inconclusive — capability detection gates editor preload, so a single blip would otherwise leave the editor degraded until the next preload runs. - Comment why only `sites/<id>/` is probed, not the `sites/<host>/` fallback GutenbergKit also emits: the WP.com proxy resolves both forms through the same backend, so a 404 on one is a 404 on the other. Tests: MUST_NOT_REMOVE now uses an Atomic site with an app password and asserts Basic (not Bearer) on the direct-host probe; new test pins the no-app-password skip; cancellation test switched to runCurrent() so the new timeout doesn't fire on virtual-time advance.
Contributor
🤖 Build Failure AnalysisThis build has failures. Claude has analyzed them - check the build annotations for details. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Summary
wp-block-editor/v1/settingsin its route list but the actual call 404s — most visibly on JPC sandboxes likeprotective-artifact-leopard.jurassic.ninja.MUST_NOT_REMOVEpinned test.Root cause
EditorSettingsRepository.fetchRouteSupportaskedapiRoot().get()whether/wp-block-editor/v1/settingswas registered. For JPC sites the WP.com proxy advertises/wp-block-editor/v1/sites/<host>/settingsin its route list — but hitting that same path returns 404 because the underlying site never registered it. Capability detection said "supported," the editor opened, then the editor's actual settings fetch 404'd.Confirmed by curl against
protective-artifact-leopard.jurassic.ninja: the proxy's?rest_route=/sites/<host>/discovery lists the route, both/wp-json/?rest_route=/sites/<host>/wp-block-editor/v1/settingsand/wp-block-editor/v1/sites/<host>/settingsreturn 404.Fix
1. Direct endpoint probes
Replace the route-list scan in
EditorSettingsRepositorywith direct OkHttp probes:Probes are cancellable (
suspendCancellableCoroutine+Call.cancelviainvokeOnCancellation) so dangling preloads don't keep sockets open after the scope is torn down.Each attempt is bounded by a 5s timeout — rather than inheriting the
REGULARclient's 60s read timeout — and a transport-level Inconclusive is retried once. Capability detection gates editor preload, so a single network blip would otherwise leave the editor degraded until the next preload runs.2. Preserve Atomic direct-host routing
GutenbergKit fetches
wp-block-editor/v1/settingsfrom the direct host on Atomic sites — it bypassessiteApiRootfor this one endpoint. Capability detection routes the probe accordingly via aforceDirectHostflag at the call site, with aMUST NOT REMOVEcomment block citing #22879 / #22883.The direct-host probe authenticates with the site's application password (Basic), never the WP.com bearer — the direct host doesn't honor the bearer, and we don't want to send WP.com credentials to whatever host
wpApiRestUrlpoints at. Atomic sites that haven't minted an app password yet (e.g. before the headless mint completes) return Inconclusive and leave the cached pref alone until the next preload.401/403 still counts as Supported here — that's the stale-or-rotated-app-password case, where the route exists but the credential was rejected.
The asymmetry — only settings bypasses, not editor-assets — is also pinned with a test.
3. Probe answer is now authoritative
getSupportsEditorSettingsForSiteprefers the probe result onceAppPrefs.hasSiteEditorCapabilitiesreturns true, falling back to the legacyEditorSettingsTablerow as the first-launch fast-path. Avoids the regression of a stale legacy row overriding a probe that correctly answeredfalse.4. Shared auth-header helper
buildAuthHeaderextracted fromGutenbergKitSettingsBuilderintoEditorAuthHeaderBuilderso the probe and the editor cannot drift on Bearer-vs-Basic selection.What we explored
hasExistingSQL row check entirely. ❌ Regresses first-launch UX on sites where the probe hasn't completed yet. UsehasSiteEditorCapabilitiesas the gate instead.ReactNativeStore.executeGetRequest. ❌ Has a destructive side-effect of clearingwpApiRestUrlon 404 (ReactNativeStore.kt:232-247), which would re-run discovery just to probe an endpoint.wpLoginClient.apiDiscovery()route-list check on the direct host (matches Probe direct host for editor capability detection on Atomic sites #22883 exactly). ❌ Doesn't catch the proxy-advertises-but-doesn't-serve case; probing the actual endpoint is more direct.REGULARclient (5s per-attempt timeout, retry once). ✅ Chosen.Test plan
/wp-block-editor/v1/settingsreturns 404 (e.g. fresh JN sandbox). Open My Site, let the preloader settle, open Site Settings — "Use Theme Styles" should be unsupported. Open the editor — should launch successfully without theme styles, no stall.automatticwidgets.wpcomstaging.com(or another Atomic site). Confirm Site Settings reports capability correctly and the editor opens — this is the protection from Probe direct host for editor capability detection on Atomic sites #22883 we must not regress.editor-assetsprobe).Unit tests:
./gradlew :WordPress:testJetpackDebugUnitTest --tests EditorSettingsRepositoryTest— passes (probe outcomes, Atomic app-password gate, direct-host Basic auth, timeout/retry, cancellation)./gradlew :WordPress:testJetpackDebugUnitTest --tests EditorAuthHeaderBuilderTest— 13 passes./gradlew :WordPress:testJetpackDebugUnitTest --tests GutenbergKitSettingsBuilderTest— passes (regression: existing tests unaffected by helper extraction)EditorCapabilityResolverTest,GutenbergEditorPreloaderTest,SiteConnectivityBannerViewModelSliceTestRelated
wpApiRestUrlduring editor preload #22903 (wpApiRestUrlpreload recovery — same class of editor-launch-failure root cause)