Skip to content

fix(backend): NSFW検出モデルが file:// で読み込めない問題を修正 (tfjs-node external化後の tfjs-core 分裂)#17528

Merged
kakkokari-gtyih merged 1 commit into
misskey-dev:developfrom
ikaskey:fix-nsfw-model-file-url-scheme
Jun 2, 2026
Merged

fix(backend): NSFW検出モデルが file:// で読み込めない問題を修正 (tfjs-node external化後の tfjs-core 分裂)#17528
kakkokari-gtyih merged 1 commit into
misskey-dev:developfrom
ikaskey:fix-nsfw-model-file-url-scheme

Conversation

@sasagar
Copy link
Copy Markdown
Contributor

@sasagar sasagar commented Jun 2, 2026

What

packages/backend/rolldown.config.tsnsfwjs@tensorflow/* ファミリ全体を external 化します (これまでは @tensorflow/tfjs-node のみ external)。

Fixes #17527.

 		/^@napi-rs\/.*/,
-		'@tensorflow/tfjs-node',
+		/^@tensorflow\/.*/,
+		'nsfwjs',

Why

#17501@tensorflow/tfjs-node をバンドル外に出して以降、センシティブメディア検出 (NSFW) が以下のエラーで壊れていました。

TypeError: node-fetch cannot load file:///.../packages/backend/nsfw-model/model.json. URL scheme "file" is not supported.

@tensorflow/tfjs-nodefile://IOHandler自身が参照する @tensorflow/tfjs-core に登録します。しかし nsfwjs (とその依存の @tensorflow/tfjs@tensorflow/tfjs-core) はバンドル内に残っていたため、実行時に tfjs-core のインスタンスが 2 つに分裂 していました。nsfwjs.load()file:// router を持たないバンドル内 tfjs-core 上で動き、HTTP ハンドラ → AiService が差し込んだ node-fetch にフォールバックして file:// が拒否されます。

nsfwjs@tensorflow/* を external 化することで TF.js スタック全体が単一の dedupe 済み @tensorflow/tfjs-core (いずれも 4.22.0) に解決され、tfjs-node が登録した file:// IOHandler が共有されます。根本原因の詳細は #17527 を参照してください。

バンドルへの影響はありません。packages/backend/src 内でのこれらのモジュールの参照は import type (ビルド時に消去) と await import(...) (動的) のみで、バンドルが静的に import している箇所は無いため、これらは既に external な @tensorflow/tfjs-node と同様に node_modules から解決される実行時 require になるだけです。

Additional info (optional)

稼働中の 2026.5.4 インスタンス (Node 22.22.2 / develop + #17068 + #17501 ビルド) で検証しました。

[1] external な @tensorflow/tfjs-node  loadLayersModel(file://) => OK (318 layers)
[2] external な nsfwjs (node_modules)  .load(file://)           => OK
[3] tfjs-core 4.22.0 / tfjs 4.22.0 / tfjs-node 4.22.0 (一致 → 単一インスタンスに dedupe)

[2] は修正後の解決経路 (nsfwjs を external 解決 → 単一 tfjs-core を共有) をそのまま再現し、file:// でのモデル読み込みが復活することを確認しています。ローカルでのフルバンドル再ビルドは未実施ですが、バンドルビルド自体は CI で検証され、本変更は既存の externalModules 配列にエントリを追加するのみ (@sentry / @napi-rs / slacc で既に使われている RegExp 形式と同じ) です。

Checklist

  • Read the contribution guide
  • Test working in a local environment (稼働中インスタンスで externalize 後のモデル読み込み経路を実証。Additional info 参照)
  • (If needed) Add story of storybook
  • (If needed) Update CHANGELOG.md
  • (If possible) Add tests

misskey-dev#17501 で `@tensorflow/tfjs-node` を bundle 外に出した結果、bundle 内の
`nsfwjs` が抱える `@tensorflow/tfjs-core` と external な tfjs-node が使う
tfjs-core が別インスタンスに分裂し、tfjs-node が登録する `file://` IOHandler を
nsfwjs 側が共有できなくなった。このため nsfwjs のモデル読み込みが HTTP handler
(node-fetch) にフォールバックし `URL scheme "file" is not supported` で失敗する。

`nsfwjs` と `@tensorflow/*` も external 化し、単一の tfjs-core インスタンスに
統一することで file:// IOHandler を共有させる。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Jun 2, 2026
@github-actions github-actions Bot added the packages/backend Server side specific issue/PR label Jun 2, 2026
@sasagar sasagar changed the title fix(backend): NSFW model fails to load via file:// after externalizing tfjs-node (#17527) fix(backend): NSFW検出モデルが file:// で読み込めない問題を修正 (tfjs-node external化後の tfjs-core 分裂) Jun 2, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 24.91%. Comparing base (97a667e) to head (2f11e5a).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #17528      +/-   ##
===========================================
+ Coverage    15.22%   24.91%   +9.68%     
===========================================
  Files          247     1160     +913     
  Lines        12349    39562   +27213     
  Branches      4196    11013    +6817     
===========================================
+ Hits          1880     9856    +7976     
- Misses        8196    23804   +15608     
- Partials      2273     5902    +3629     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 2, 2026

このPRによるapi.jsonの差分
差分はありません。
Get diff files from Workflow Page

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 2, 2026

Backend memory usage comparison

Before GC

Metric base (MB) head (MB) Diff (MB) Diff (%)
VmRSS 305.41 MB 300.21 MB -5.19 MB -1.70%
VmHWM 305.41 MB 300.21 MB -5.19 MB -1.70%
VmSize 23171.14 MB 23165.10 MB -6.04 MB -0.02%
VmData 1371.44 MB 1365.69 MB -5.75 MB -0.41%

After GC

Metric base (MB) head (MB) Diff (MB) Diff (%)
VmRSS 305.47 MB 300.30 MB -5.16 MB -1.69%
VmHWM 305.47 MB 300.30 MB -5.16 MB -1.69%
VmSize 23171.23 MB 23165.52 MB -5.71 MB -0.02%
VmData 1371.53 MB 1366.10 MB -5.42 MB -0.39%

After Request

Metric base (MB) head (MB) Diff (MB) Diff (%)
VmRSS 305.96 MB 300.69 MB -5.27 MB -1.72%
VmHWM 305.96 MB 300.69 MB -5.27 MB -1.72%
VmSize 23171.39 MB 23165.52 MB -5.87 MB -0.02%
VmData 1371.69 MB 1366.10 MB -5.58 MB -0.40%

See workflow logs for details

sasagar added a commit to ikaskey/misskey that referenced this pull request Jun 2, 2026
NSFW 検出モデルが file:// で読み込めない問題の修正 (cherry-pick) を含む。
upstream: misskey-dev#17528

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@kakkokari-gtyih kakkokari-gtyih merged commit d5ab422 into misskey-dev:develop Jun 2, 2026
49 of 58 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in [実験中] 管理用 Jun 2, 2026
@kakkokari-gtyih
Copy link
Copy Markdown
Member

🙏

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

Labels

packages/backend Server side specific issue/PR size:S This PR changes 10-29 lines, ignoring generated files.

Projects

Development

Successfully merging this pull request may close these issues.

センシティブメディア検出(NSFW)のモデルが URL scheme "file" is not supported で読み込めない (#17501 後のリグレッション)

2 participants