fix(plugins): hold the write lock for the plugin cap checks on Postgres

meta.set and scheduler.set checked their caps in a transaction of the
repository's own, which keeps check and write together on SQLite's single
writer but not on Postgres, where two pool connections both read the same
count. Both RPCs now run the capped write inside UnitOfWork.transactional,
which takes the engine's write lock; the repository's transaction becomes a
savepoint of it.
This commit is contained in:
Maurice
2026-11-17 12:07:57 +01:00
parent 54b843ae29
commit 60642cc18b
7 changed files with 51 additions and 24 deletions
+2
View File
@@ -641,6 +641,7 @@ export async function createPluginRpcHostParts(
await createTestDaysRepo(db),
await createTestReservationsRepo(db),
await createTestDayAccommodationsRepo(db),
await createTestUnitOfWork(db),
),
// Plan 3j Task 5 — HostSurfaceRpc's own HR1/HR5–HR9 conversion: the plugin-visible
// user row, the bilateral trip-sharing gate, and its own scheduler.set/cancel.
@@ -655,6 +656,7 @@ export async function createPluginRpcHostParts(
usersRepo,
await createTestTripsRepo(db),
pluginOrm.repo(PluginScheduledTasks),
await createTestUnitOfWork(db),
),
new PluginHooks(undefined as never),
];
+11 -1
View File
@@ -94,7 +94,16 @@ export function allRpcControllers(): object[] {
// Plan 3j Task 5 — MetaRpc/HostSurfaceRpc's own repository conversions (MR#/HR#).
// Plan 4 Task 2 — both classes' own DatabaseService param is gone (canAccessTrip
// now reads through the TripsRepository they already inject), one fewer anyService().
new MetaRpc(anyService(), anyService(), anyService(), anyService(), anyService(), anyService(), anyService()),
new MetaRpc(
anyService(),
anyService(),
anyService(),
anyService(),
anyService(),
anyService(),
anyService(),
anyService(),
),
new HostSurfaceRpc(
anyService(),
anyService(),
@@ -105,6 +114,7 @@ export function allRpcControllers(): object[] {
anyService(),
anyService(),
anyService(),
anyService(),
),
// Owns no wire method, but declares all 18 hook contracts, which requireTotalCoverage checks too.
new PluginHooks(anyService()),
+5 -1
View File
@@ -22,6 +22,7 @@ import { PluginGuards } from '../../../src/nest-rpc/plugin-guards.service';
import { PluginRpcRegistryService } from '../../../src/nest-rpc/rpc-kit/registry.service';
import { createTestPluginRegistry } from '../../../src/nest-rpc/rpc-kit/testing';
import type { AddonsService } from '../../../src/nest/addons/addons.service';
import type { UnitOfWork } from '../../../src/nest/database/unit-of-work';
import { UnreadableLlmResponse } from '../../../src/nest/llm-parse/clients/openai-compatible.client';
import type { LlmConfigResolver } from '../../../src/nest/llm-parse/llm-config.resolver';
import type { NotificationsService } from '../../../src/nest/notifications/notifications.service';
@@ -397,9 +398,11 @@ const usersRepo = {
// params are gone: canAccessTrip now reads through the TripsRepository each
// already injects (`tripsRepo` above, findAccessible-only).
const guards = new PluginGuards(tripsRepo, permissions, addons, usersRepo);
/** The capped writes run in a unit of work; the stand-in repositories here are atomic on their own. */
const uow = { transactional: <T>(fn: () => Promise<T>) => fn() } as unknown as UnitOfWork;
const registry = createTestPluginRegistry([
new DbRpc(userSettings),
new MetaRpc(guards, metaRepo, tripsRepo, placesRepo, daysRepo, reservationsRepo, dayAccommodationsRepo),
new MetaRpc(guards, metaRepo, tripsRepo, placesRepo, daysRepo, reservationsRepo, dayAccommodationsRepo, uow),
new HostSurfaceRpc(
realtime,
notifications,
@@ -410,6 +413,7 @@ const registry = createTestPluginRegistry([
usersRepo,
tripsRepo,
scheduledTasksRepo,
uow,
),
]);
const factory = new PluginRpcHostFactory(pluginAuditRepo, registry as unknown as PluginRpcRegistryService);