Why Moodle Sends No Grades Back Over LTI Advantage
Grades exist in Moodle, the platform shows nothing, and no error appears anywhere obvious. The things that actually stop LTI Advantage grade sync in Moodle 4.5, and how to tell them apart from the task log.
Grades exist in Moodle, the platform shows nothing, and no error appears anywhere obvious. This guide covers the things that actually stop LTI Advantage grade sync in Moodle 4.5, how to tell them apart from the task log, and what to fix for each.
If you are still setting the connection up, start with Configuring LTI 1.3 in Moodle. That guide covers registration, publishing, and launch errors. This one picks up afterwards, when launches work and grades do not move.
First, establish which side Moodle is on
Moodle sits on both sides of LTI, and the two sides are different code with different failure modes.
- Moodle as the Tool publishes a course or activity out to another system, and pushes grades back to it. This is the
enrol_ltiplugin, under Site administration > Plugins > Enrolments > Publish as LTI tool. - Moodle as the Platform launches somebody else’s tool from inside a course, and receives grades from it. This is the
mod_ltiplugin, the External tool activity.
Most of the causes below sit on the Tool side. One of them only bites on the Platform side. Getting this backwards will cost you an afternoon, so settle it before you start.
A note on vocabulary: LTI 1.1 called these roles Tool Consumer and Tool Provider. LTI 1.3 and LTI Advantage call them Platform and Tool. They map onto each other one for one, and Moodle’s interface uses the 1.3 terms.
Read the task log before touching anything
LTI Advantage grade sync runs as a scheduled task, separately from the legacy LTI 1.1 sync. Moodle 4.5 ships four related tasks:
enrol_lti\task\sync_grades legacy LTI 1.1/2.0
enrol_lti\task\sync_members legacy LTI 1.1/2.0
enrol_lti\local\ltiadvantage\task\sync_grades LTI Advantage
enrol_lti\local\ltiadvantage\task\sync_members LTI Advantage
All four are scheduled every 30 minutes by default. The Advantage grade task is a dispatcher: it finds the published resources with grade sync enabled and queues one adhoc task per resource, so the useful output comes from those adhoc runs rather than from the scheduled task itself. That adhoc class is enrol_lti\local\ltiadvantage\task\sync_tool_grades; it will not appear in the scheduled task list because it is not one, and every log line quoted below comes from it.
Run it directly and read the output:
sudo -u www-data php admin/cli/scheduled_task.php \
--execute='\enrol_lti\local\ltiadvantage\task\sync_grades'
sudo -u www-data php admin/cli/adhoc_task.php \
--classname='\enrol_lti\local\ltiadvantage\task\sync_tool_grades'
Use --classname on the second command, not a bare --execute. --execute on its own runs every queued adhoc task on the site, which on a live installation means course deletions, backups and message sends all firing while you are debugging something unrelated.
Running a task this way ignores its schedule, so you do not have to wait for the next window. If the site has cron disabled, add --force to both commands or nothing will run.
The log lines are specific enough to route you to a cause. These are the ones that matter:
Found 2 resource link(s) for the user '431', for the resource '7' and the course '19'. Attempting to sync grades for all.
Processing resource link 'a1b2c3'.
Skipping - No grade service found for the user '431', for the resource '7' and the course '19'.
Skipping - Course not completed for the user ...
Skipping - Activity not completed for the user ...
Skipping - Invalid grade for the user ...
Skipping - Invalid grademax for the user ...
Not sent - The grade for the user ... was not sent as the grades are the same.
Success - The grade '0.78' for the user ... was sent.
Failed - The grade '0.78' for the user ... failed to send.
Client error: `POST https://platform.example.com/lti/scores` resulted in a `401 Unauthorized` response
The last pair is what a rejected send actually looks like: the failure message followed by the exception text, not by a status line. There is a Header: line in this code path too, but ignore it. It never carries anything useful on a real site, and a 401 does not reach it in any case, because the service connector throws, retries once with a fresh access token, and then rethrows into the handler above.
The grade in those lines is normalized, not the raw gradebook value. The task divides the grade by the grade item’s maximum before logging, so a 78 out of 100 appears as 0.78. The message sent to the platform carries the raw score and the maximum as separate values, which is why the log and the payload look different.
If you see no lines at all, start at the top of the output. The dispatcher gives up before doing anything and says so when either the LTI authentication plugin or the LTI enrollment plugin is disabled, both of which produce a Skipping task - ... line and nothing further. Two further causes produce no line whatsoever: an enrollment instance that is not enabled, and a resource without grade sync enabled. Check all four before auditing anything per-resource.
Cause A: the platform never granted the grade service
This is the most common cause and the least obvious, because nothing is misconfigured on the Moodle side.
In LTI Advantage, grades are written through Assignment and Grade Services. The tool does not have a fixed grade endpoint. It receives the line item service URLs inside the launch message itself, in the AGS claim, and stores them against the resource link at that moment.
Moodle only stores those URLs if the launch actually carried them. If the platform sends a launch with no AGS claim, or with a claim that carries no line item URLs, the resource link is created with empty grade service fields and can never sync. The task then reports:
Skipping - No grade service found for the user ...
The storage decision looks at the URLs alone, so scopes are a separate matter. A launch that supplies the URLs but not the required scopes stores them happily and then fails at the service call instead, with a missing-scope error rather than the line above. Different symptom, different fix.
Find the affected resource links:
SELECT rl.id, rl.resourcelinkid, rl.ltideploymentid, rl.resourceid,
rl.lineitemsservice, rl.lineitemservice
FROM mdl_enrol_lti_resource_link rl
WHERE COALESCE(rl.lineitemsservice, '') = ''
AND COALESCE(rl.lineitemservice, '') = ''
AND rl.resourceid = :resourceid;
Use COALESCE rather than IS NULL: the code treats an empty string as an absent service too, so a plain null test misses those rows. Scope it to a resource, or a site of any size will return more than you want. mdl_ is the default table prefix; check $CFG->prefix if yours differs, and bind the parameter through your client rather than pasting it in.
The fix is on the platform, not in Moodle. Whoever administers the platform has to enable the grade services for that tool registration and grant the line item scopes. Editing the Moodle database does not help, because the URLs are platform-generated and specific to the deployment.
The critical operational detail: these values are captured at launch time. Enabling grade services on the platform does nothing to resource links that already exist. Some launch has to happen after the change before the URLs are stored.
That launch does not have to be a learner’s. The service URLs live on the resource link, not on the user, so one test launch of the same placement by whoever administers the platform repairs the record for everybody on that link. Say so when you report the fix, otherwise the client waits for learners to drift back before anything works.
Cause B: sync is working and deliberately declining to send
A large share of reported grade sync failures are not failures. Beyond cause A, the task checks four more conditions and moves on to the next user or resource link at the first one that is not met, so a single skip does not stop the run.
- Sync on completion is enabled but the work is not complete. If the published resource has grade sync tied to completion, a course-level resource requires course completion and an activity-level resource requires the activity to be complete, or complete with a passing grade. You get
Skipping - Course not completedorSkipping - Activity not completed. - There is no usable grade. An empty grade, or one that fails the internal check, produces
Skipping - Invalid grade. - The grade item has no maximum. LTI Advantage sends a score together with a maximum, so a grade item with an empty or zero maximum cannot be expressed. This gives
Skipping - Invalid grademax. - The grade has not changed. Moodle stores the last value it sent per user and does not resend an identical grade. This produces
Not sent - ... the grades are the same.
That fourth one is worth spelling out to clients. If the platform lost its copy of the grade, Moodle will not push it again on its own, because from Moodle’s point of view nothing changed.
The safe way to force a resend is through the gradebook: change the grade, let a sync run, then change it back. Each edit is a real difference, so both runs transmit. Moodle keeps the last value it sent in mdl_enrol_lti_users.lastgrade, and clearing that column has the same effect, but it is a direct write to a live table with no interface behind it. If you go that route, take a backup first, scope the update to the specific users, and treat it as a last resort rather than routine maintenance.
A fifth line, and this one is a real failure
Alongside those four skips the task can emit one more line, and this one is a genuine fault rather than a deliberate decision. An invalid context id on the published resource logs Failed - Invalid contextid '<id>' for the resource '<id>', and two things make it easy to miss. It says Failed rather than Skipping, so a grep for Skipping will not show it, and it names no user, so a per-user grep will not show it either. If a resource produces nothing at all for anybody, look for this line explicitly. The fix is the resource’s context, not any of the four conditions above.
Cause C: leftovers from an LTI 1.1 migration
Sites that ran LTI 1.1 before moving to LTI Advantage often end up with users attached to both stacks at once. The two stacks store different things:
- The legacy path keeps the outcome endpoint in
mdl_enrol_lti_users.serviceurl, with the consumer identified throughmdl_enrol_lti_tool_consumer_map. - The Advantage path keeps the endpoints in
mdl_enrol_lti_resource_link, joined to users throughmdl_enrol_lti_user_resource_link.
There is a unique index on mdl_enrol_lti_resource_link over resourcelinkid and ltideploymentid, so genuine duplicate rows for one deployment cannot occur. What does occur is the same platform-side link existing once per deployment, and a user carrying both a legacy record and one or more Advantage links.
Be careful how you read Found 2 resource link(s) in the log. That count comes from the Advantage tables alone, and the task only iterates users who already have a deployment id, so it never counts legacy records. Two resource links means the same user reached the same published resource through two Advantage links, typically two placements or two deployments on the platform. It is not evidence of a 1.1 leftover. For that, look at the database rather than the log.
See what a user actually has:
SELECT lu.id, lu.userid, lu.toolid, lu.ltideploymentid,
CASE WHEN COALESCE(lu.serviceurl, '') <> '' THEN 1 ELSE 0 END AS haslegacyservice,
COUNT(url.id) AS advantagelinks
FROM mdl_enrol_lti_users lu
LEFT JOIN mdl_enrol_lti_user_resource_link url ON url.ltiuserid = lu.id
WHERE lu.userid = :userid
GROUP BY lu.id, lu.userid, lu.toolid, lu.ltideploymentid, lu.serviceurl;
A row with haslegacyservice = 1 and advantagelinks above zero is a user sitting on both stacks.
Moodle supports the standard migration path for this. A platform can include the lti1p1 claim in an Advantage launch, handing over the old OAuth consumer key so the tool can recognize the connection as the same one. Moodle stores it on the deployment:
SELECT d.id, d.name, d.deploymentid, d.platformid, d.legacyconsumerkey
FROM mdl_enrol_lti_deployment d
WHERE d.legacyconsumerkey IS NOT NULL;
If legacyconsumerkey is populated, the platform is sending the migration claim and Moodle can link old and new identities. If it is empty and you know the site came from LTI 1.1, the platform is not sending it, and the two stacks will stay separate. At that point the honest choice is to retire the legacy tool deployment on the platform, have the connection recreated against the Advantage deployment, and accept that historical grade state on the old path stays where it is.
Do not delete rows from these tables to tidy up. Removing a resource link removes the only copy of the platform-issued service URLs, and there is no way to reconstruct them short of a fresh launch.
Cause D: a 401 when Moodle is the platform
This one is on the receiving side. When Moodle is the Platform, an external tool calls back into Moodle to write grades and read memberships, and it authenticates with a bearer token:
Authorization: Bearer eyJhbGciOi...
Moodle reads that header through its own helper rather than a framework. If apache_request_headers() is available it uses that. Otherwise it scans $_SERVER for keys beginning HTTP_, which means the header has to reach PHP as $_SERVER['HTTP_AUTHORIZATION'] or Moodle never sees it. Under PHP-FPM, Apache does not pass the Authorization header through by default, so the tool gets a 401 for a token that was perfectly valid.
On Apache 2.4.13 and later, CGIPassAuth does this. Note its context: the directive is only valid in a directory section or an .htaccess file, so it goes inside a <Directory> block, not directly under <VirtualHost>. Putting it at virtual host level produces a configuration error.
There is a second condition, and it is the one that catches people out. A <Directory> block only applies once Apache has mapped the URL to a filename. If PHP is wired up with ProxyPassMatch, which maps in URL space and skips that step, the <Directory> section is never consulted and CGIPassAuth has no effect at all. Check which form your virtual host uses before concluding the directive does not work.
<VirtualHost *:443>
ServerName your-moodle-site.example.com
DocumentRoot /var/www/moodle
# SetHandler keeps the normal URL-to-filename mapping, so <Directory> applies.
<FilesMatch "\.php$">
SetHandler "proxy:unix:/run/php/php-fpm.sock|fcgi://localhost/"
</FilesMatch>
<Directory /var/www/moodle>
CGIPassAuth On
</Directory>
</VirtualHost>
If your virtual host uses ProxyPassMatch instead, either convert it to the SetHandler form above or use the SetEnvIf route below, which works either way. To put CGIPassAuth in an .htaccess file rather than the vhost, the directory also needs AllowOverride AuthConfig.
On older Apache builds, and on any ProxyPassMatch setup, set the variable explicitly. SetEnvIf is valid at virtual host level:
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
Prefer either of those to the widely circulated mod_rewrite variant. In .htaccess or directory context that one triggers an internal redirect, so the value arrives as REDIRECT_HTTP_AUTHORIZATION, and Moodle’s header helper reads only keys prefixed HTTP_. The token is present and Moodle cannot see it.
Under nginx with PHP-FPM the header normally survives, since request headers are passed through by default. If you do set it explicitly, set it alongside the rest of the parameter set rather than on its own. nginx inherits fastcgi_param values from an outer level only when the current block defines none, so a lone line here silently drops SCRIPT_FILENAME and everything with it.
location ~ \.php$ {
include fastcgi.conf;
fastcgi_param HTTP_AUTHORIZATION $http_authorization;
fastcgi_pass unix:/run/php/php-fpm.sock;
}
Note which file that is. nginx ships both fastcgi_params and fastcgi.conf, and the difference matters here: only fastcgi.conf sets SCRIPT_FILENAME. Including fastcgi_params and nothing else gives you a block that passes the authorization header to a PHP process that cannot work out which script to run.
Prove the fix rather than trusting the config. Put a small script inside the webroot, request it with a token, then remove it:
<?php
var_dump($_SERVER['HTTP_AUTHORIZATION'] ?? 'NOT SET');
Save that as authcheck.php in the webroot. Reload the web server first, because the configuration change does nothing until you do:
sudo systemctl reload apache2 # or, on nginx: sudo systemctl reload nginx
Then send a request carrying the header:
curl -H "Authorization: Bearer testvalue" https://your-moodle-site.example.com/authcheck.php
If that prints NOT SET, no amount of work on the LTI configuration will help. Delete the file once you are done.
Note that this applies equally to LTI 1.1, where the inbound call carries an OAuth header instead of Bearer. Both go through the same code path in Moodle, so a site that strips the header breaks both versions.
Cause E: the platform rejects Moodle’s access token
This is the mirror image of cause D. There, Moodle is the Platform and cannot read an inbound token. Here Moodle is the Tool, sends a score outward, and the platform refuses it. The log shows the send failing with the exception text rather than a status line:
Failed - The grade '0.78' for the user ... failed to send.
Client error: `POST https://platform.example.com/lti/scores` resulted in a `401 Unauthorized` response
Read the second line before assuming which failure this is, because three different problems share the first one.
The platform rejected the score itself. The exception names the scores endpoint, as in the sample above. Moodle asked for an access token successfully, sent the score, and got a 401 back. It had already retried once with a freshly minted token before surfacing this, so a transient expiry is not the explanation. What is left is the platform’s view of the registration, and the usual cause is a client id that no longer matches: a tool re-registered on the platform side gets a new one, and Moodle keeps the old.
Moodle could not get a token at all. The exception names the platform’s token endpoint rather than the scores endpoint. This failure happens before any score is sent and is not retried, because the token request sits outside the retry. Check that the token endpoint Moodle holds is the platform’s current one and is reachable from the Moodle server; a platform that has moved domains often leaves the old address answering with a redirect or an error page.
The launch never carried the score scope. The second line reads Missing required scope and nothing else. Moodle checks the scope in its own code and throws, so unlike the other two this message names no URL and no HTTP status, which is how you tell it apart at a glance. This is the one that looks like cause A and is not, because the resource link does have its endpoints. The scopes are stored per resource link rather than on the registration, so look at scorescope on the link:
SELECT rl.id, rl.resourcelinkid, rl.lineitemscope, rl.scorescope
FROM mdl_enrol_lti_resource_link rl
WHERE rl.resourceid = :resourceid;
An empty scorescope means the platform’s AGS claim did not grant it. The fix is on the platform, and like cause A it only takes effect on a fresh launch, because the scope is captured at launch time along with the endpoints.
None of the three is fixed in Moodle’s configuration or in the web server. If the platform is somebody else’s system, this is the point to hand it over, with the log line attached so they can tell which of the three it is.
Which one is it
Five questions. Take them in this order, because the first one splits the whole problem in half:
- Is Moodle sending grades or receiving them? If Moodle is the Platform, receiving service calls and returning 401, that is cause D and the fix is in the web server configuration. Everything below is about Moodle sending.
- Does the task log say
Skipping - No grade service found? Cause A. Fix it on the platform, then launch the same placement again, from any account. - Does the log say
SkippingorNot sentfor another reason? Cause B. The sync is working as designed and the answer is usually a conversation, not a change. - Does the database show a legacy
serviceurland one or more Advantage resource links for the same user? Cause C. Note that this comes from the query, not from the log:Found 2 resource link(s)counts Advantage links only and is not evidence of a 1.1 leftover. - Does the log say
Failed - The grade ... failed to send? Cause E. Read the line after it: a 401 naming the scores endpoint, a failure naming the token endpoint, andMissing required scopeare three different problems with three different fixes, and none of them is in your web server configuration.
What to check before you call it fixed
Grade sync is asynchronous and rate-limited by the scheduled task, so a successful configuration change does not produce an instant result. For any of the Tool-side causes, confirm three things in sequence after a fix: a fresh launch has happened, the adhoc task has run, and the log shows Success - The grade ... was sent for a real user. For cause D, where Moodle is the Platform, the equivalent proof is the header probe returning a value rather than NOT SET. Anything short of that is an assumption.
Solin builds and troubleshoots LTI integrations between Moodle, Totara, and third-party platforms.
Contact us