Skip to content

Optimized-image polling calls the SDK before initialization #1162

Description

@pirate-bot

Status (2026-10-11)

Fixed in PR #1172 (bugfix/1162 → development, approved by pirate-bot at dd5dcd13).

  • Fix: poll_optimized_images() returns an empty list when the site is not connected, before it calls the API. It built image URLs through the SDK, which is only initialized for a connected site, and threw Please initialize the Optimole SDK first.
  • Tests: with no connection, polling returns success with an empty list and sends no request. The test fails on development with that exception.
  • Not proven: the dashboard's empty state was not checked in a browser.

Summary

When optimized-image polling receives a nonempty image list while the Optimole image SDK is uninitialized, URL generation throws an uncaught runtime exception instead of completing the REST response. This leaves the polling request failed and prevents the dashboard from receiving its image results.

Customer context

  • Product / area: Optimole WordPress plugin, optimized-image REST polling
  • Version: 4.2.13 and 4.2.14
  • Environment: Reported across WordPress 6.9.9–7.1.2 and PHP 8.2–8.5
  • Integration / third party: Optimole image SDK; Themeisle SDK versions 3.3.61 and 3.3.62 were also present
  • Reported error / symptom: Please initialize the Optimole SDK first. during REST polling
  • Impact: The affected polling request terminates before returning image results.

Reproduction notes

Telemetry reports the exception during a REST polling request in versions 4.2.13 and 4.2.14. A source-indicated reproduction condition is a nonempty optimized-image API response when the site is not connected and the image SDK has therefore not been initialized; this condition was not runtime-reproduced. Existing tests cover nonempty results only with CDN connection settings present.

Diagnosis

Conclusion

The product's REST polling callback can reach URL generation without ensuring the image SDK was initialized. Initialization of the media-offload singleton is conditional on the site's connected state, while the polling callback proceeds for a nonempty API response. This is a reachable product-side precondition gap consistent with the reported exception. The exact settings and SDK state on the affected requests were not captured.

Where this likely occurs

  • inc/rest.php — Optml_Rest::poll_optimized_images(), lines 708–733, calls the API and sends every returned image through Optml_Media_Offload::instance()->get_media_optimized_url() when the list is nonempty.
  • inc/media_offload.php — Optml_Media_Offload::instance(), lines 154–162, invokes its initialization path only when Optml_Settings::is_connected() is true.
  • inc/settings.php — Optml_Settings::is_connected(), lines 189–198, requires both CDN key and secret.
  • inc/app_replacer.php — Optml_App_Replacer::get_optimized_image_url(), lines 664–681, calls Optimole::image() for URL generation.
  • inc/config.php — Optml_Config::init(), lines 95–149, initializes the image SDK during the normal connected setup.
  • inc/api.php — Optml_Api::get_optimized_images(), lines 344–355, accepts an API key for the request independently of the connection check above. The telemetry shows that the callback reached image URL generation with a nonempty list.

Engineering notes

The behavior is reported in product versions 4.2.13 and 4.2.14, and the same conditional initialization path is present in the inspected 4.2.14 source. No regression boundary was identified. The exception's source dependency was not present in the workspace; the recorded stack identifies it as coming from codeinwp/optimole-sdk, while the product caller and initialization lifecycle were inspected locally. The REST route uses the default manage_options permission callback in inc/rest.php, lines 189–232, so the reported surface is an authenticated REST request.

Test coverage status

tests/test-poll-optimized-images.php covers successful nonempty polling at lines 188–218, but its setup supplies CDN key and secret at lines 22–33. Error and empty-list cases are also covered. No relevant test was found for a nonempty response with the SDK uninitialized. Tests were not run.

What to verify or explore next

  • May be worth verifying polling with a valid API response while CDN connection settings are absent or incomplete.
  • If reproducing against a tagged release, checking whether the REST request can occur during or immediately after disconnection would clarify the triggering state.
  • The affected sites' saved service data and initialization state are not available in this report.

Unknowns / follow-up

The telemetry does not identify the API-key state, connection settings, or request timing on the affected sites. The actual deployed codeinwp/optimole-sdk source was not available in this workspace for independent inspection.

Confidence

Confidence: 82/100

One product-side initialization precondition gap is confirmed in the REST polling path and no matching open GitHub issue was found. The other three crashes are not confirmed code defects: the reported SDK file and both product classes exist in the reported release with reachable load paths, so the telemetry is consistent with transient or inconsistent runtime files.

Crash telemetry

Occurrences 5
Distinct sites 2
First seen 2026-09-23 15:21 UTC
Last seen 2026-09-23 19:46 UTC
Crash location product:vendor/codeinwp/optimole-sdk/src/Optimole.php:80
Request context rest
Inside Themeisle SDK no
Product versions 4.2.13, 4.2.14
WP versions 6.9.9, 7.1.2
PHP versions 8.2.15, 8.2.33
SDK versions 3.3.61, 3.3.62

Source: automated crash report — optimole-wp, fingerprint 929319f2cd6aedc1c371f0cdb334d42a
Generated by bug-report-triage (ID: bug-report-triage_6ab60e5e41a8e2.77469449)

Activity

  1. added theissue type on Sep 25, 2026
  2. self-assigned this
    on Oct 9, 2026
  3. milicavs commented on Oct 11, 2026

    @milicavs

    🧪 QA steps and test links

    When the Optimole dashboard treats the site as connected but the site has no CDN key and secret saved (an incomplete or just-removed connection), the dashboard's "Latest 10 images" request crashes with Please initialize the Optimole SDK first. and returns nothing. Normal use rarely reaches that state, so a Code Snippet below fakes it, together with an account that has optimized images.

    Link Build Bot check
    Reproduce the bug Optimole 4.2.16 (released) ✅ Reproduced: the dashboard opens as Connected, and its poll_optimized_images request comes back with an empty response instead of JSON
    Verify the fix PR #1172 build dd5dcd1 ✅ Fixed: the same request returns {"data":[],"code":"success"}. The dashboard then refreshes the account and, with the fake key, switches to Not connected

    In the links:

    • Steps 1 and 2 are already done (a seeded setting plus a must-use plugin instead of the snippet), and the links open on the Optimole dashboard.
    • The release shows a "disabled due to exceeding quota" notice: the fake account data has no status. Ignore it.
    • Playground doesn't write this crash to debug.log; on a regular server the error shows in the PHP log. Tools → QA Logs shows debug.log.

    Reproduce on Optimole 4.2.16 (a site that isn't connected to Optimole, with Code Snippets):

    1. Snippets → Add New, title QA: half-connected Optimole, paste the code below, then Save Changes and Activate.
    2. Open Optimole, then reload the page once. The header shows Connected.
    3. Open the browser's dev tools → Network, filter for poll_optimized_images, and reload the page.
    • Bug: the request fails (500 or an empty response), and the PHP error log has Please initialize the Optimole SDK first.
    • Fixed: the request returns {"data":[],"code":"success"}, and nothing is logged.
    // Dashboard data without a CDN key and secret.
    add_action( 'admin_init', function () {
    	$s = get_option( 'optml_settings', [] );
    	if ( empty( $s['service_data'] ) ) {
    		$s['api_key']      = 'qa-fake-key';
    		$s['service_data'] = [ 'plan' => 'free', 'app_count' => 1 ];
    		update_option( 'optml_settings', $s, false );
    	}
    } );
    // Answer the "last optimized images" API call with one image.
    add_filter( 'pre_http_request', function ( $pre, $args, $url ) {
    	if ( false === strpos( $url, '/optml/v1/stats/images' ) ) {
    		return $pre;
    	}
    	return [ 'headers' => [], 'cookies' => [], 'filename' => null, 'response' => [ 'code' => 200, 'message' => 'OK' ],
    		'body' => wp_json_encode( [ 'code' => 200, 'data' => [ 'list' => [ [ 'url' => 'https://example.com/photo.jpg', 'key' => 'AbC' ] ] ] ] ) ];
    }, 10, 3 );
    Edge cases
    • Deactivate the snippet and connect a real Optimole account: "Latest 10 images" shows optimized images as before.
    • Not connected at all (fresh install, no snippet): the dashboard shows the connect screen, with no errors in the console or log.
    • Disconnect from the dashboard on a connected site: no Optimole SDK error in the PHP log afterwards.

    Fix: #1172 (open)

  4. pirate-bot commented on Oct 11, 2026

    @pirate-bot
    CollaboratorAuthor

    QA agent — 🟡 Needs human QA · Disconnected polling is fixed; connected thumbnail display remains unverified.

    With an incomplete connection and a nonempty image fixture, the dashboard returned an empty success response and displayed its empty state. The base build reproduced the failure, while the candidate passed the same journey and the new regression test. Disconnecting and no-key loads worked, and missing-credential checks passed across PHP 8.2–8.5. Connected polling still produces image URLs, but thumbnail display needs verification with a real account.

    Worth a human look

    1. Open the dashboard with a real connected Optimole account and confirm Last optimized images thumbnails load.
    Checks (3 passed · 1 not tested)
    • ✅ Opening the Optimole dashboard with absent or incomplete CDN connection data makes optimized-image polling return success with an empty list, without calling the optimized-image API or throwing the SDK initialization error.
    • ✅ After disconnected optimized-image polling completes, the dashboard's Last optimized images box displays its empty state rather than remaining in loading placeholders.
    • ✅ The Optimole dashboard loads without an SDK initialization error when no API key is saved and after disconnecting through the dashboard; the disconnected connect screen remains usable after reload.
    • ⏸️ Opening the connected Optimole dashboard still shows the account's optimized images in the Last optimized images box.

    Full report, evidence and session trail

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions