Troubleshooting¶
This file is the fast path for debugging the current Moodle-on-wasm SQLite prototype.
For the full migration history and rationale, see sqlite-wasm-migration-notes.md.
Quick checks¶
Runtime debug mode in the browser:
Use this first when debugging runtime/bootstrap issues. It forces Moodle
developer debug mode and enables PHP display_errors for the booted session.
Accepted values include true, developer, normal, minimal, and 0.
Syntax:
node --check sw.js
node --check php-worker.js
node --check src/runtime/bootstrap.js
node --check src/runtime/php-loader.js
node --check src/remote/main.js
node --check lib/moodle-loader.js
php -l patches/shared/lib/dml/sqlite3_pdo_moodle_database.php
php -l patches/shared/lib/ddl/sqlite_sql_generator.php
php -l patches/shared/lib/classes/encryption.php
Bundle and runtime:
Keep the installed PHP-WASM packages and emitted assets aligned with the lockfile; rebuild both workers after runtime/SW changes and clear old Service Worker caches. Reset Playground clears site data, not worker code.
Slow JavaScript navigation or a missing RequireJS combine¶
Moodle owns jsrev; generated config.php must not pin it to1. New seeds announce
snapshot.jsrev and contain requirejs/<sha1(revision)> plus requirejs/revision.
An advertised mismatch fails during extraction. Legacy seeds and changed revisions
use the existing per-module fallback; rebuild the snapshot/seed to regain a matching
combine. Do not rename an old combine to a newer plugin/purge revision.
Only public immutable production ESM is cached by the SW; authenticated HTML,
protected files and development ESM still execute PHP. See
ADR-0033 and
ADR-0034.
Blueprint provisioning on persisted reload¶
New instances store completed steps in the SQLite checkpoint. Reload restores
declared volatile files and saved plugins/overlays, recreates login, and skips
persisted data mutations and arbitrary PHP/HTTP requests. A previously unfinished
step remains an error rather than being retried automatically. Legacy instances
without checkpoints log a warning; do not clear valuable data just to silence it.
If the blueprint behind the same URL changed, reload keeps the data, runs only
login/landing and warns; use Reset Playground to apply the new blueprint.
Back up before an explicit Reset/rebuild. Runtime code edits outside declared steps
are not persistent. Plugin/theme ZIPs are downloaded again on reload (no copy is
kept, ADR-0036). A failed download is retried twice; if it still fails the log names
the archive (Failed to download plugin ZIP from …) and the plugin stays missing
from disk until a reload with network access. The checkpoint keeps the SHA-256 of
each installed archive (ADR-0037): when the URL serves a newer version on reload,
the code is installed, the log warns and Moodle asks for the upgrade on the next
admin page; when it serves different content without a newer version — or an older
one than the retained DB, e.g. after a manual plugin upgrade — extraction is skipped
with a warning. Use Reset Playground to install the current archive. See
ADR-0035 and
ADR-0037.
Restored plugins/overlays invalidate MUC, both hookcallbacks.php registries,
DI and bytecode without changing JS/theme revisions. An overlay with
purgeCaches:false skips this: remove that opt-out when restored callbacks or
strings remain stale. MUC alone does not invalidate Moodle's on-disk hook lists.
Blueprint persistence flush reports elapsed milliseconds, hydrated bytes and
operations. Quota failures or unavailable persistence warn that reload may lose
this session's changes; they do not block using the live instance. Back up before
reloading. Do not delete failed plugin artifacts: partially applied schema may
still require that code. Skipped arbitrary PHP warns about unrestored volatile files.
First place to look¶
If the browser is failing during install or first load, inspect these in order:
- browser console
- network requests for
/playground/main/php83-cgi/... - shell progress log
PHP Infopanel- rerun with
?debug=trueif the page is hiding PHP/Moodle errors
The most useful files for runtime debugging are:
src/runtime/bootstrap.jssrc/remote/main.jssw.jssrc/runtime/php-compat.jslib/moodle-loader.js
Symptoms¶
TypeError: resolved is not a function¶
Likely cause:
- malformed or unreadable
install.xml - a regression in the XML/runtime path outside the current common patch set
Notes:
- if this happens during schema load, inspect the
install.xmlfile first and re-run the XMLDB load checks against the current unpatched Moodle sources
Fatal in sqlite_sql_generator¶
Examples:
- signature mismatch with
sql_generator - missing
getCreateTempTableSQL
Files:
patches/shared/lib/ddl/sqlite_sql_generator.php
Notes:
- this is a Moodle-core compatibility problem, not a wasm routing problem
Fatal in sqlite3_pdo_moodle_database¶
Examples:
is_temptable() on null- driver returns
falsewhen Moodle 5 expects[] - deprecated
reset()on object
Files:
patches/shared/lib/dml/sqlite3_pdo_moodle_database.php- runtime override in
src/runtime/bootstrap.js
Fatal in admin/plugins.php: Failed opening required '…/analytics/tests/classes/mlbackend_helper_trait.php'¶
Likely cause:
- the core bundle excludes every
*/tests/*directory (ADR 0011), but some Moodle 5.0+ production coderequire_once()s a file that lives undertests/.lib/mlbackend/python/classes/processor.phprequires the analytics test traitcore_analytics\tests\mlbackend_helper_trait. Building the admin tree instantiates everymlbackendplugin (core_analytics\manager::get_all_prediction_processors()), so loading/admin/plugins.php(or any analytics admin page) fatals on the excluded file.
Files:
scripts/patch-moodle-source.sh(drops the test-traitrequire_once/useand inlines the only method the class actually uses)docs/architecture/adr/ADR-0014-production-require-of-tests-files-patch.md
Notes:
make up-localdoes NOT reproduce this — it serves the full checkout withtests/present. Reproduce/verify only against a real bundle (make bundle).- If a different Moodle branch fatals on another
…/tests/…require, generalize this into a build-time detector (see ADR 0014 Review Criteria).
Invalid cache store in config warnings everywhere¶
Likely cause:
- Missing cache store/admin defaults or a stale cache configuration; normal
web requests keep MUC enabled (
CACHE_DISABLE_ALL=false).
Files:
src/runtime/config-template.js- runtime override in
src/runtime/bootstrap.js
Notes:
- do not disable MUC globally to suppress them; verify seeded cache defaults
- if they become fatal again, inspect
cache/classes/config.phpandcache/classes/cache.php
Undefined constant "core\\SODIUM_CRYPTO_SECRETBOX_NONCEBYTES"¶
Likely cause:
- the current WASM runtime does not ship
sodium - some Moodle paths still assume sodium-first encryption unless the local fallback patch is active
Files:
patches/shared/lib/classes/encryption.php- runtime override in
src/runtime/bootstrap.js src/runtime/config-template.js
Current workaround:
rememberusernameis disabled by defaultcore\\encryptionfalls back to OpenSSL in this prototypeadmin/environment.xmlis downgraded at runtime so upgrades are not blocked by the missing extension
Undefined array key "HTTP_USER_AGENT"¶
Likely cause:
- PHP request handler did not expose request headers as standard
HTTP_*variables
File:
src/runtime/php-compat.js
No input file specified. for styles_debug.php, javascript.php, yui_combo.php¶
Likely cause:
- scoped URL/request rewriting mismatch between the Service Worker and PHP request handler
Files:
sw.jssrc/runtime/php-compat.jssrc/runtime/php-loader.js
What to inspect:
- request URL seen by the Service Worker
- forwarded request URL sent to the php worker
- computed
SCRIPT_NAMEandSCRIPT_FILENAMEin the PHP request handler
ERR_TOO_MANY_REDIRECTS or "Incorrect access detected"¶
Likely cause:
$CFG->wwwrootbuilt from the wrong base URL- or scoped redirects losing query parameters
Files:
src/runtime/bootstrap.jsphp-worker.jssw.jssrc/shared/storage.js
Timed out while waiting for php-worker readiness¶
Likely cause:
- bootstrap JS error before
worker-ready - stale service worker / stale scope
- bundle load failure
Files:
php-worker.jssrc/remote/main.jssrc/runtime/bootstrap.js
Immediate actions:
- hard reload
Reset- check shell log for the last bootstrap step reached
- retry with
?debug=trueto surface hidden PHP/bootstrap errors
Outbound HTTPS from PHP behaves differently depending on the target¶
Likely cause:
tcpOverFetchis active, but not every HTTPS destination behaves the same- the configured
phpCorsProxyUrlfallback does work for the non-TLS path;tests/e2e/php-networking.spec.mjscovers an HTTP request that fails direct and succeeds through the configured proxy - direct HTTPS now works for the real eXeLearning GitHub releases feed and the
real tested release ZIP asset (
v4.0.0-beta3) - direct HTTPS now works for a CORS-open external URL such as
raw.githubusercontent.com - direct HTTPS to a self-signed local HTTPS server still fails before fallback; the browser-side fetch performed by the runtime does not trust that local certificate
- the same-origin proxy path is still available if a plugin wants a stable, explicit playground-only contract
What the tests currently prove:
tests/e2e/php-networking.spec.mjs- same-origin proxy path works
- configured
phpCorsProxyUrlfallback works for HTTP requests - direct HTTPS works for a CORS-open external URL
- direct HTTPS works for the eXeLearning GitHub feed
- direct HTTPS works for the eXeLearning GitHub release ZIP asset
- direct HTTPS to a self-signed local HTTPS server still fails
tests/runtime/tcp-over-fetch-certificates.test.js- the generated CA parses as a CA in OpenSSL
- a runtime-style leaf signed by that CA verifies in OpenSSL
- the upstream ASN.1 encoder still mis-encodes explicit
keyUsageand SAN IP extensions (IP Address:<invalid>, unexpected key usage), so the runtime must avoid those extensions until upstream is fixed
What is supported:
- direct PHP requests to trusted external HTTPS origins, including the tested
CORS-open
raw.githubusercontent.comURL - direct PHP requests to the tested eXeLearning GitHub feed and release ZIP URLs
phpCorsProxyUrlas the browser-side fallback for PHP networkingMOODLE_PLAYGROUND_PROXY_URLas an explicit same-origin PHP networking endpoint when a plugin prefers a stable playground-only proxy contract- the same-origin proxy endpoint is validated by
tests/e2e/php-networking.spec.mjs
Files:
src/runtime/php-loader.jssw.jssrc/runtime/config-template.jstests/e2e/php-networking.spec.mjs
Site is still in English after setting the language (or langimport fails with CORS)¶
Likely cause:
- Moodle bundles only English; other languages are separate packs that must be downloaded into
dataroot/lang/<code>. Settinglang/localealone only changes the preference. - If
admin/tool/langimportfails with a CORS error ondownload.moodle.org/langpack/<v>/languages.md5, the github-proxy is not authorizing the langpack index.
What works now:
- The github-proxy allowlists
/langpack/paths (incl.languages.md5) ondownload.moodle.organdpackaging.moodle.org, so the native Site administration → Language → Language packs UI installs directly. Downloads route throughphpCorsProxyUrlviatcpOverFetch. - Works in Chromium, Firefox, and Safari — language packs are GET requests, which avoid the
duplex: 'half'streaming-request-body limit that breaks Firefox/Safari WASM outbound (POST uploads). That limit is why some other outbound PHP calls still fail on those browsers. - Blueprints: use the
installLanguagePackstep, or just set the site language (installMoodleoptions.locale) — the pack auto-installs on boot (runLanguageAutoInstall()inbootstrap.js).
If it still fails: confirm the proxy is deployed with the langpack allowance
(isMoodleLangpackUrl in scripts/github-proxy-worker.js) and reachable, and that
phpCorsProxyUrl is set in playground.config.json.
Files:
scripts/github-proxy-worker.jssrc/blueprint/steps/moodle-language.jssrc/runtime/bootstrap.js(runLanguageAutoInstall)docs/architecture/adr/ADR-0006-moodle-langpack-proxy-allowance.md
Course restore (restoreCourse) fails or the course is missing¶
Likely cause:
- The
.mbzis large/complex. Restore runs entirely in the WASM runtime, which has limited memory and a SQLite driver that crashes on nested savepoints (ADR-0003). Big backups (many activities, large files, completion/calendar data) can exceed memory or hit transaction limits and fail. - The
urlis not reachable: the host must be CORS-accessible (e.g.raw.githubusercontent.com) or proxy-allowlisted, otherwise the in-PHP download fails.
What to expect / do:
- A failed restore is reported in the boot log and is non-fatal — the rest of the blueprint still runs (ADR-0005). The course simply won't be created.
- Prefer smaller course backups. Host large
.mbzat a CORS URL so it streams into the runtime (theurlsource) instead of being buffered (thedatasource). - The download is a GET over
tcpOverFetch, so it works in Chromium, Firefox and Safari (unlike streaming-upload POSTs). If it fails only in one browser, check the URL's CORS headers.
Files:
src/blueprint/steps/moodle-restore.jssrc/blueprint/php/helpers.js(phpRestoreCourse)docs/architecture/adr/ADR-0007-course-restore-step.md
PHP worker bridge timed out¶
Likely cause:
- the worker is alive but the request handler is blocked
- often follows a fatal in PHP or a very slow/stuck bootstrap
Files:
php-worker.jssrc/remote/main.jssrc/runtime/bootstrap.js
White iframe, but URL/title inside Moodle are correct — resolved¶
This was previously the most visible browser-side issue but has been resolved.
The recovery watchdog in src/remote/main.js is still present as a safety net.
If this symptom reappears after changes to routing or bootstrap:
src/remote/main.js— inspectisFrameDocumentStalled(),scheduleFrameRecovery()sw.js— check HTML response rewritingsrc/runtime/php-compat.js— check$_SERVERvariable construction
RangeError: Array buffer allocation failed — resolved¶
This was caused by the bundle loader double-buffering (chunk buffers + full output buffer).
Fixed by preallocating a single destination buffer when content-length is known.
If this reappears after changes to the loader, inspect lib/moodle-loader.js.
Warnings like Undefined property: stdClass::$frontpage¶
Likely cause:
- bootstrap path skipped normal config hydration
- missing defaults in generated
config.phpor persistedconfigtable
Files:
src/runtime/config-template.jssrc/runtime/bootstrap.js
Defaults currently seeded:
navcourselimitenablecompletionfrontpagefrontpageloggedinfrontpagecourselimitguestloginbuttonrememberusernameauth_instructionsmaintenance_enabledmaxbytes
SQLite driver bugs (upstream)¶
If the error originates from the DML/DDL layer (sqlite3_pdo_moodle_database.php or
sqlite_sql_generator.php), it is a driver bug that must be fixed in two places:
- The upstream fork ateeducacion/moodle (3 maintained branches for Moodle tracker PRs)
- The local patch copies in this repository under
patches/shared/lib/dml/andpatches/shared/lib/ddl/
This repository maintains its own independent copies of the SQLite driver files.
The build pipeline clones official Moodle and overlays these local patches — it does
NOT pull from the ateeducacion/moodle fork. Fixing only the fork will NOT fix the playground.
Workflow:
- Reproduce and fix on the
mdl-88218-workbenchbranch usingmake up(local PHP + SQLite) - Replicate the fix to all three maintained upstream branches
- Also apply the fix to
patches/shared/lib/dml/orpatches/shared/lib/ddl/in this repo - Trigger a manual rebuild via GitHub Actions (Run workflow → select
main)
See .agents/references/sqlite-upstream-workflow.md for the full procedure.
Example: ddltablenotexist — Table "backup_ids_temp" does not exist¶
Root cause: fetch_columns() only queried sqlite_master but SQLite stores
temporary tables in sqlite_temp_master. Fixed by adding UNION ALL with
sqlite_temp_master (#48).
If install fails mid-way¶
Inspect the staged bootstrap messages from src/runtime/bootstrap.js:
core:startcore:schema-load:startcore:schema-load:donecore:schema-sql:count=...plugins:startfinalize:startthemes:start
If failure happens:
- before
core:schema-load:done - inspect XMLDB patches
- during schema SQL execution
- inspect SQLite DDL generator / DML driver
- during
finalize - inspect config hydration and brittle plugin settings files
- after install, on first real navigation
- inspect
wwwroot, redirects, asset URLs, CGI env, and iframe recovery
Extension reality in this repo¶
The @php-wasm/web PHP runtime (available for versions 8.1–8.5, default 8.3) includes all required extensions built into the WASM binary:
dom,iconv,intl,libxml,simplexml,xml,zip,mbstring,openssl,sqlite3,pdo_sqlite,phar,curl,gd,fileinfo,xmlreader,xmlwriter
Note: sodium is not available in this runtime; the repository relies on the OpenSSL fallback
patches documented elsewhere. Also note that curl is available as an extension but actual
network requests from WASM are constrained (uses fetch-based transport, not real sockets). When
playground.config.json defines phpCorsProxyUrl, the runtime can use that proxy as the
browser-side fallback for outbound PHP HTTP(S) traffic through @php-wasm/web TCP-over-fetch.
This is separate from addonProxyUrl, which is used for browser-side ZIP/plugin downloads and
for the explicit same-origin Service Worker proxy endpoint. If outbound requests still fail,
verify the configured PHP CORS proxy supports general HTTP(S) proxying, not just ZIP downloads.
Scope already open in another tab¶
Each scope permits one active owner, including when PHP versions differ. Close the owning tab and reload the rejected tab, or open a new scope. A rejected tab does not reset the journal. Web Locks must be available and permitted; there is no concurrent-owner fallback. Reload and Reset release the old worker before reacquiring ownership. See ADR-0041.