mirror of
https://github.com/the-draupnir-project/Draupnir.git
synced 2026-06-08 00:21:40 +00:00
Remove Mjolnir's ErrorCache.
A bizarre contraption. The ErrorCache was seemingly introduced to reduce the number of errors in the management room. https://github.com/matrix-org/mjolnir/commit/82214c6cd88d83abed05fec4a871a874e6e0265b It makes sense why it was added if you consider that many admins will run Draupnir without giving it the permission to manage server ACL in its rooms. Though, I'm not sure why then you would add the error cache rather than properly supporting that use case. So perhaps there were other reasons. Either way, what is drawing the line for me is that the ErrorCache will suppress any error within rooms that is not a permission error, if there was any error that was not a permission error within a 15 minute window. Considering the typical Draupnir will not even sync for hours at a time, even in large communities. It does present a problem for rooms with a lot of join/leave events. I think that's probably why the error cache was added. Ahh, well, fuck. Well what is the real solution to this? The real solution when the kind is acl is to allow the bot to run without applying ACLs. Ok fine but, hey wait a minute. Why would there be any other kind of persistent error when banning someone that would be unimportant enough to silently hide in an ErrorCache?? IDK let's just add an opttion to disable server ACL, since they might want to use another tool for that anyhow. Out of scope for the current work though. https://github.com/Gnuxie/Draupnir/pull/85
This commit is contained in:
@@ -1,89 +0,0 @@
|
||||
/**
|
||||
* Copyright (C) 2022 Gnuxie <Gnuxie@protonmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is modified and is NOT licensed under the Apache License.
|
||||
* This modified file incorperates work from mjolnir
|
||||
* https://github.com/matrix-org/mjolnir
|
||||
* which included the following license notice:
|
||||
|
||||
Copyright 2019 The Matrix.org Foundation C.I.C.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*
|
||||
* However, this file is modified and the modifications in this file
|
||||
* are NOT distributed, contributed, committed, or licensed under the Apache License.
|
||||
*/
|
||||
|
||||
export const ERROR_KIND_PERMISSION = "permission";
|
||||
export const ERROR_KIND_FATAL = "fatal";
|
||||
|
||||
const TRIGGER_INTERVALS: { [key: string]: number } = {
|
||||
[ERROR_KIND_PERMISSION]: 3 * 60 * 60 * 1000, // 3 hours
|
||||
[ERROR_KIND_FATAL]: 15 * 60 * 1000, // 15 minutes
|
||||
};
|
||||
|
||||
/**
|
||||
* The ErrorCache is used to suppress the same error messages for the same error state.
|
||||
* An example would be when mjolnir has been told to protect a room but is missing some permission such as the ability to send `m.room.server_acl`.
|
||||
* Each time `Mjolnir` synchronizes policies to protected rooms Mjolnir will try to log to the management room that Mjolnir doesn't have permission to send `m.room.server_acl`.
|
||||
* The ErrorCache is an attempt to make sure the error is reported only once.
|
||||
*/
|
||||
export default class ErrorCache {
|
||||
private roomsToErrors: Map<string/*room id*/, Map<string /*error kind*/, number>> = new Map();
|
||||
|
||||
constructor() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the error cache for a room/kind in the situation where circumstances have changed e.g. if Mjolnir has been informed via sync of a `m.room.power_levels` event in the room, we would want to clear `ERROR_KIND_PERMISSION`
|
||||
* so that a user can see if their changes worked.
|
||||
* @param roomId The room to reset the error cache for.
|
||||
* @param kind The kind of error we are resetting.
|
||||
*/
|
||||
public resetError(roomId: string, kind: string) {
|
||||
if (!this.roomsToErrors.has(roomId)) {
|
||||
this.roomsToErrors.set(roomId, new Map());
|
||||
}
|
||||
this.roomsToErrors.get(roomId)?.set(kind, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the error with the cache.
|
||||
* @param roomId The room where the error is occuring or related to.
|
||||
* @param kind What kind of error, either `ERROR_KIND_PERMISSION` or `ERROR_KIND_FATAL`.
|
||||
* @returns True if the error kind has been triggered in that room,
|
||||
* meaning it has been longer than the time specified in `TRIGGER_INTERVALS` since the last trigger (or the first trigger). Otherwise false.
|
||||
*/
|
||||
public triggerError(roomId: string, kind: string): boolean {
|
||||
if (!this.roomsToErrors.get(roomId)) {
|
||||
this.roomsToErrors.set(roomId, new Map());
|
||||
}
|
||||
|
||||
const triggers = this.roomsToErrors.get(roomId)!;
|
||||
if (!triggers.has(kind)) {
|
||||
triggers?.set(kind, 0);
|
||||
}
|
||||
|
||||
const lastTriggerTime = triggers.get(kind)!;
|
||||
const now = new Date().getTime();
|
||||
const interval = TRIGGER_INTERVALS[kind];
|
||||
|
||||
if ((now - lastTriggerTime) >= interval) {
|
||||
triggers.set(kind, now);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,13 +28,12 @@ limitations under the License.
|
||||
import { LogLevel, LogService, MatrixGlob, UserID } from "matrix-bot-sdk";
|
||||
import { Permalinks } from "./commands/interface-manager/Permalinks";
|
||||
import { IConfig } from "./config";
|
||||
import ErrorCache, { ERROR_KIND_FATAL, ERROR_KIND_PERMISSION } from "./ErrorCache";
|
||||
import ManagementRoomOutput from "./ManagementRoomOutput";
|
||||
import { MatrixSendClient } from "./MatrixEmitter";
|
||||
import AccessControlUnit, { Access } from "./models/AccessControlUnit";
|
||||
import { RULE_ROOM, RULE_SERVER, RULE_USER } from "./models/ListRule";
|
||||
import PolicyList, { ListRuleChange, Revision } from "./models/PolicyList";
|
||||
import { RoomUpdateError } from "./models/RoomUpdateError";
|
||||
import { ERROR_KIND_FATAL, ERROR_KIND_PERMISSION, RoomUpdateError } from "./models/RoomUpdateError";
|
||||
import { ProtectionManager } from "./protections/ProtectionManager";
|
||||
import { EventRedactionQueue, RedactUserInRoom } from "./queues/EventRedactionQueue";
|
||||
import { ProtectedRoomActivityTracker } from "./queues/ProtectedRoomActivityTracker";
|
||||
@@ -75,8 +74,6 @@ export class ProtectedRoomsSet {
|
||||
*/
|
||||
private readonly eventRedactionQueue = new EventRedactionQueue();
|
||||
|
||||
private readonly errorCache = new ErrorCache();
|
||||
|
||||
/**
|
||||
* These are globs sourced from `config.automaticallyRedactForReasons` that are matched against the reason of an
|
||||
* `m.ban` recommendation against a user.
|
||||
@@ -205,8 +202,6 @@ export class ProtectedRoomsSet {
|
||||
}
|
||||
this.protectedRoomActivityTracker.handleEvent(roomId, event);
|
||||
if (event['type'] === 'm.room.power_levels' && event['state_key'] === '') {
|
||||
// power levels were updated - recheck permissions
|
||||
this.errorCache.resetError(roomId, ERROR_KIND_PERMISSION);
|
||||
await this.managementRoomOutput.logMessage(LogLevel.DEBUG, "Mjolnir", `Power levels changed in ${roomId} - checking permissions...`, roomId);
|
||||
const errors = await this.protectionManager.verifyPermissionsIn(roomId);
|
||||
const hadErrors = await this.printActionResult(errors);
|
||||
@@ -481,7 +476,6 @@ export class ProtectedRoomsSet {
|
||||
if (errors.length <= 0) return false;
|
||||
|
||||
if (!logAnyways) {
|
||||
errors = errors.filter(e => this.errorCache.triggerError(e.roomId, e.errorKind));
|
||||
if (errors.length <= 0) {
|
||||
LogService.warn("Mjolnir", "Multiple errors are happening, however they are muted. Please check the management room.");
|
||||
return true;
|
||||
|
||||
@@ -25,6 +25,9 @@ limitations under the License.
|
||||
* are NOT distributed, contributed, committed, or licensed under the Apache License.
|
||||
*/
|
||||
|
||||
export const ERROR_KIND_PERMISSION = "permission";
|
||||
export const ERROR_KIND_FATAL = "fatal";
|
||||
|
||||
export interface RoomUpdateError {
|
||||
roomId: string;
|
||||
errorMessage: string;
|
||||
|
||||
@@ -39,7 +39,7 @@ import { LogLevel, LogService } from "matrix-bot-sdk";
|
||||
import { ProtectionSettingValidationError } from "./ProtectionSettings";
|
||||
import { Consequence } from "./consequence";
|
||||
import { htmlEscape } from "../utils";
|
||||
import { ERROR_KIND_FATAL, ERROR_KIND_PERMISSION } from "../ErrorCache";
|
||||
import { ERROR_KIND_FATAL, ERROR_KIND_PERMISSION } from "../models/RoomUpdateError";
|
||||
import { RoomUpdateError } from "../models/RoomUpdateError";
|
||||
import { BanPropagation } from "./BanPropagation";
|
||||
import { MatrixDataManager, RawSchemedData, SchemaMigration, SCHEMA_VERSION_KEY } from "../models/MatrixDataManager";
|
||||
|
||||
@@ -25,7 +25,7 @@ limitations under the License.
|
||||
* are NOT distributed, contributed, committed, or licensed under the Apache License.
|
||||
*/
|
||||
import { LogLevel, MatrixClient } from "matrix-bot-sdk"
|
||||
import { ERROR_KIND_FATAL } from "../ErrorCache";
|
||||
import { ERROR_KIND_FATAL } from "../models/RoomUpdateError";
|
||||
import { RoomUpdateError } from "../models/RoomUpdateError";
|
||||
import { redactUserMessagesIn } from "../utils";
|
||||
import ManagementRoomOutput from "../ManagementRoomOutput";
|
||||
|
||||
Reference in New Issue
Block a user