Skip to content

Conversation

@kakkokari-gtyih
Copy link
Contributor

@kakkokari-gtyih kakkokari-gtyih commented Jan 6, 2026

What

rolldownでバックエンドをバンドル(e2e用のみswcから移行していない)

途中まで起動するがここで固まる。同じような状況に遭遇していたら情報が欲しいかも

image

Why

Additional info (optional)

Checklist

  • Read the contribution guide
  • Test working in a local environment
  • (If needed) Add story of storybook
  • (If needed) Update CHANGELOG.md
  • (If possible) Add tests

@github-actions
Copy link
Contributor

github-actions bot commented Jan 6, 2026

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

@kakkokari-gtyih
Copy link
Contributor Author

kakkokari-gtyih commented Jan 6, 2026

コード54.4MBになった(が、起動には成功してない)

@syuilo
Copy link
Member

syuilo commented Jan 6, 2026

@syuilo
Copy link
Member

syuilo commented Jan 6, 2026

通常ならその直後に InstanceLoader: EndpointsModule dependencies initialized が出るからEndpointsModuleに原因がある可能性がある

@syuilo
Copy link
Member

syuilo commented Jan 6, 2026

どっちかというと EndpointsModule というよりは EndpointsModule に依存している ServerModule かも

@samunohito
Copy link
Member

関係あるかわからないけど…

クラス名は維持しておかないとDI周りが死ぬので、バンドルの過程でクラス名などが変わっているのであれば維持するようにしてみるといいかも…?

@syuilo
Copy link
Member

syuilo commented Jan 6, 2026

どっちかというと EndpointsModule というよりは EndpointsModule に依存している ServerModule かも

いやさらに ServerModule に依存している CoreModule かも
CoreModule が含んでいる何らかの Service のどれかに問題がありそう(SearchServiceのログは出てるから最低でもそこまでは読み込めていることは判る)

@syuilo
Copy link
Member

syuilo commented Jan 6, 2026

いかのどれかに問題があることは絞り込めた

		AbuseUserReportEntityService,
		AnnouncementEntityService,
		AbuseReportNotificationRecipientEntityService,
		AntennaEntityService,
		AppEntityService,
		AuthSessionEntityService,
		BlockingEntityService,
		ChannelEntityService,
		ChatEntityService,
		ClipEntityService,
		DriveFileEntityService,
		DriveFolderEntityService,
		EmojiEntityService,
		FollowingEntityService,
		FollowRequestEntityService,
		GalleryLikeEntityService,
		GalleryPostEntityService,
		HashtagEntityService,
		InstanceEntityService,
		InviteCodeEntityService,
		ModerationLogEntityService,
		MutingEntityService,
		RenoteMutingEntityService,
		NoteEntityService,
		NoteFavoriteEntityService,
		NoteReactionEntityService,
		NoteDraftEntityService,
		NotificationEntityService,
		PageEntityService,
		PageLikeEntityService,
		SigninEntityService,
		UserEntityService,
		UserListEntityService,
		FlashEntityService,
		FlashLikeEntityService,
		RoleEntityService,
		ReversiGameEntityService,
		MetaEntityService,

@kakkokari-gtyih
Copy link
Contributor Author

クラス名は維持しておかないとDI周りが死ぬ

keepNamesしてるのでそれはなさそう

@syuilo
Copy link
Member

syuilo commented Jan 6, 2026

NoteEntityService に問題があることが判った

@syuilo
Copy link
Member

syuilo commented Jan 6, 2026

NoteEntityServiceは循環参照があり、読み込み順的にはModuleRefを使用する初めてのサービスであるので、ModuleRefを使用していることが原因ということで間違いないと思われる

@codecov
Copy link

codecov bot commented Jan 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 63.19%. Comparing base (6e99acf) to head (9e05bde).
⚠️ Report is 1 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #17068      +/-   ##
===========================================
+ Coverage    63.09%   63.19%   +0.10%     
===========================================
  Files         1152     1154       +2     
  Lines       115196   115410     +214     
  Branches      7976     8023      +47     
===========================================
+ Hits         72680    72938     +258     
+ Misses       40369    40325      -44     
  Partials      2147     2147              

☔ 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.

@syuilo
Copy link
Member

syuilo commented Jan 6, 2026

NoteEntityServiceは循環参照があり、読み込み順的にはModuleRefを使用する初めてのサービスであるので、ModuleRefを使用していることが原因ということで間違いないと思われる

いや嘘かも

@syuilo
Copy link
Member

syuilo commented Jan 6, 2026

InstanceEntityServiceだけ読み込まれてないかも

@syuilo
Copy link
Member

syuilo commented Jan 6, 2026

謎ということが判った

@syuilo
Copy link
Member

syuilo commented Jan 6, 2026

とはいえ循環参照周りが原因な気はする

@anatawa12
Copy link
Member

バンドルでesmoduleそのままだと発生しない循環参照問題が発生するなら minify だけにしたい気がしてます。今後devなら問題ないのにbuildすると謎フリーズが今後増えるのはあまりうれしくないと思います

@syuilo
Copy link
Member

syuilo commented Jan 6, 2026

ApAudienceService も正常に読み込まれていないserviceのひとつだけど、以下のように極限にシンプルな実装に書き換えると読み込まれるようになる

before

import { Injectable } from '@nestjs/common';
import promiseLimit from 'promise-limit';
import type { MiRemoteUser, MiUser } from '@/models/User.js';
import { concat, unique } from '@/misc/prelude/array.js';
import { bindThis } from '@/decorators.js';
import { getApIds } from './type.js';
import { ApPersonService } from './models/ApPersonService.js';
import type { ApObject } from './type.js';
import type { Resolver } from './ApResolverService.js';

type Visibility = 'public' | 'home' | 'followers' | 'specified';

type AudienceInfo = {
	visibility: Visibility,
	mentionedUsers: MiUser[],
	visibleUsers: MiUser[],
};

type GroupedAudience = Record<'public' | 'followers' | 'other', string[]>;

@Injectable()
export class ApAudienceService {
	constructor(
		private apPersonService: ApPersonService,
	) {
	}

	@bindThis
	public async parseAudience(actor: MiRemoteUser, to?: ApObject, cc?: ApObject, resolver?: Resolver): Promise<AudienceInfo> {
		const toGroups = this.groupingAudience(getApIds(to), actor);
		const ccGroups = this.groupingAudience(getApIds(cc), actor);

		const others = unique(concat([toGroups.other, ccGroups.other]));

		const limit = promiseLimit<MiUser | null>(2);
		const mentionedUsers = (await Promise.all(
			others.map(id => limit(() => this.apPersonService.resolvePerson(id, resolver).catch(() => null))),
		)).filter(x => x != null);

		if (toGroups.public.length > 0) {
			return {
				visibility: 'public',
				mentionedUsers,
				visibleUsers: [],
			};
		}

		if (ccGroups.public.length > 0) {
			return {
				visibility: 'home',
				mentionedUsers,
				visibleUsers: [],
			};
		}

		if (toGroups.followers.length > 0 || ccGroups.followers.length > 0) {
			return {
				visibility: 'followers',
				mentionedUsers,
				visibleUsers: [],
			};
		}

		return {
			visibility: 'specified',
			mentionedUsers,
			visibleUsers: mentionedUsers,
		};
	}

	@bindThis
	private groupingAudience(ids: string[], actor: MiRemoteUser): GroupedAudience {
		const groups: GroupedAudience = {
			public: [],
			followers: [],
			other: [],
		};

		for (const id of ids) {
			if (this.isPublic(id)) {
				groups.public.push(id);
			} else if (this.isFollowers(id, actor)) {
				groups.followers.push(id);
			} else {
				groups.other.push(id);
			}
		}

		groups.other = unique(groups.other);

		return groups;
	}

	@bindThis
	private isPublic(id: string): boolean {
		return [
			'https://www.w3.org/ns/activitystreams#Public',
			'as:Public',
			'Public',
		].includes(id);
	}

	@bindThis
	private isFollowers(id: string, actor: MiRemoteUser): boolean {
		return id === (actor.followersUri ?? `${actor.uri}/followers`);
	}
}

after

import { Injectable } from '@nestjs/common';
import type { MiRemoteUser } from '@/models/User.js';
import { bindThis } from '@/decorators.js';
import type { ApObject } from './type.js';
import type { Resolver } from './ApResolverService.js';

@Injectable()
export class ApAudienceService {
	constructor(
	) {
		console.log('ApAudienceService initialized');
	}

	@bindThis
	public async parseAudience(actor: MiRemoteUser, to?: ApObject, cc?: ApObject, resolver?: Resolver) {
		return {
			visibility: 'specified',
		};
	}
}

@kakkokari-gtyih
Copy link
Contributor Author

InstanceEntityServiceだけ読み込まれてないかも

コードに出てないわけでなさそう(ビルド成果物を検索したらヒットした)

@kakkokari-gtyih
Copy link
Contributor Author

kakkokari-gtyih commented Jan 6, 2026

バンドルでesmoduleそのままだと発生しない循環参照問題が発生するなら minify だけにしたい気がしてます。今後devなら問題ないのにbuildすると謎フリーズが今後増えるのはあまりうれしくないと思います

そもそもnestjsはバンドルされた環境で動かすことは想定されてるのかしら

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

Projects

Development

Successfully merging this pull request may close these issues.

4 participants