Closed Bug 1907977 Opened 2 months ago Closed 2 months ago

source not showing in worker

Categories

(DevTools :: Debugger, defect, P3)

defect

Tracking

(firefox130 fixed)

RESOLVED FIXED
130 Branch
Tracking Status
firefox130 --- fixed

People

(Reporter: tarek, Assigned: ochameau)

References

Details

Attachments

(2 files)

When working with a script I am trying to set some break points into an imported mjs file in a chrome worker, but I get an empty source for some of the files, and a console warning:

console warning 13223> console.warn: "source source-url-chrome://global/content/ml/ONNXPipeline.mjs/originalSource-d5b2a77756f17135cf42a6cb637bb78e

see the screenshot, notice that the root mjs file for the worker works fine. ONNXPipeline.mjs is imported.

To reproduce in mozilla-central, toggle browser.ml.enable and run this in a toolbox:

async function infere() {
const {PipelineOptions, EngineProcess } = ChromeUtils.importESModule("chrome://global/content/ml/EngineProcess.sys.mjs");
  const options = new PipelineOptions({taskName: "moz-image-to-text" });
  const engineParent = await EngineProcess.getMLEngineParent();
  const engine = engineParent.getEngine(options);
  const request = {url: "https://huggingface.co/datasets/mishig/sample_images/resolve/main/football-match.jpg"};
  const res = await engine.run(request);
  console.log(res);
}

await infere();

This will create a new content process with the worker.

Notice that I've recenty introduced an inference remote type, so maybe I did a regression https://bugzilla.mozilla.org/show_bug.cgi?id=1905599

I tried to switch back the remoteType to web and same issue, so I think that is not related

Summary of the current situation about this ONNXPipeline.mjs module with missing source:

We first load chrome://global/content/ml/MLEngine.worker.mjs
as a ChromeWorker from here:
https://searchfox.org/mozilla-central/rev/f3e4b33a6122ce63bf81ae8c30cc5ac37458864b/toolkit/components/promiseworker/PromiseWorker.sys.mjs#184
No issues in loading this module source text content.

This MLEngineWorker.worker.mjs loads ONNXPipeline.mjs via ChromeUtils.defineESModuleGetters + {current: "global"}.
So, loaded as an ESM from an ESM loaded as a ChromeWorker.

What happens in devtools is that spidermonkey Debugger API's Source.text attribute is returning [no source] string over there:
https://searchfox.org/mozilla-central/rev/f3e4b33a6122ce63bf81ae8c30cc5ac37458864b/devtools/server/actors/source.js#260
For some reason, spidermonkey looses, or do not store the source text content.
This isn't the case for most system ESMs. DevTools fetches the text content via this Source.text API.

Now, there is a fallback code, when spidermonkey misses the text content, where DevTools tries to fetch the url for text content.
But it is also broken on this very particular usecase because of this line:
https://searchfox.org/mozilla-central/rev/f3e4b33a6122ce63bf81ae8c30cc5ac37458864b/devtools/server/actors/utils/sources-manager.js#492
This complex workaround doesn't expect a source actor with no source content and actually ignore the correct content fetched by source url
and replace it with the [no source].

A workaround until this is fixed is to execute ChromeUtils.importESModule("chrome://global/content/ml/ONNXPipeline.mjs") from the main thread, before ONNXPipeline.mjs is loaded from the worker. Even it throws, the debugger will pick this up and be able to show the source.

:ochameau will check is this impacts regular (non-chrome) workers as well.

Will set priority afterwards.

Build a test case for regular workers.

Flags: needinfo?(jdescottes)

(In reply to Julian Descottes [:jdescottes] from comment #5)

Build a test case for regular workers.

Built one where we load a module worker with a ESM import:

https://turquoise-cumbersome-bottom.glitch.me/

Added setInterval in worker files so they're not killed

Looking at nicolas test page, regular DOM workers are not impacted by this issue.

I'll try to provide a fix for the source text content fallback, so that the privileged modules can be debugged.
But we should have a followup to investigate why spidermonkey doesn't expose these worker modules source content.

Severity: -- → S3
Flags: needinfo?(jdescottes)
Priority: -- → P3

Spidermonkey fails returning source text content via Source.text attribute.
It returns "[no source]" and the urlContents fallback was trying to keep using this instead
of the text content fetched via a request.

Assignee: nobody → poirot.alex
Status: NEW → ASSIGNED
Depends on: 1910497
Blocks: 1685412
Pushed by apoirot@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/f42283f2b318 [devtools] Fix source text content of worker ESM loaded via ChromeUtils methods. r=devtools-reviewers,nchevobbe
Status: ASSIGNED → RESOLVED
Closed: 2 months ago
Resolution: --- → FIXED
Target Milestone: --- → 130 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: