Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Cap the event-log bounds and share the drop type

erywim3f5a89978b38
diff --git a/server/harness/bus.test.ts b/server/harness/bus.test.ts
index d3c36eca0f..fb0f1006a7 100644
--- a/server/harness/bus.test.ts
+++ b/server/harness/bus.test.ts
@@ -459,6 +459,12 @@ describe("EventBus", () => {
OMB_EVENT_LOG_QUEUE_BYTES: "-5",
OMB_EVENT_LOG_DRAIN_THREADS: "eight",
})).toEqual({ batchLines: 512, queueEvents: 4096, queueBytes: 32 * 1024 * 1024, drainThreads: 8 });
+ expect(eventLogLimits({
+ OMB_EVENT_LOG_BATCH_LINES: "999999",
+ OMB_EVENT_LOG_QUEUE_EVENTS: "999999999999",
+ OMB_EVENT_LOG_QUEUE_BYTES: "999999999999999",
+ OMB_EVENT_LOG_DRAIN_THREADS: "9999",
+ })).toEqual({ batchLines: 4096, queueEvents: 1_000_000, queueBytes: 1024 * 1024 * 1024, drainThreads: 64 });
});
it("does not report a successful shutdown flush after an append fails", async () => {
diff --git a/server/harness/bus.ts b/server/harness/bus.ts
index 081b23fb05..357bc323b8 100644
--- a/server/harness/bus.ts
+++ b/server/harness/bus.ts
@@ -22,6 +22,8 @@ const DELTA_MERGE_MS = 50;
/** Lines per drain batch, queued events and bytes before new ones are dropped, and threads appended at once. */
const EVENT_LOG_DEFAULTS = { batchLines: 64, queueEvents: 4096, queueBytes: 32 * 1024 * 1024, drainThreads: 8 };
+/** A cap on each setting, so a mistyped size cannot switch the queue's memory guard off altogether. */
+const EVENT_LOG_MAX = { batchLines: 4_096, queueEvents: 1_000_000, queueBytes: 1024 * 1024 * 1024, drainThreads: 64 };
export interface EventLogLimits {
batchLines: number;
@@ -37,15 +39,15 @@ export interface EventLogDrops {
/** A zero, negative or non-numeric setting falls back to its default rather than stopping the log. */
export function eventLogLimits(env: Record<string, string | undefined> = process.env): EventLogLimits {
- const positive = (raw: string | undefined, fallback: number) => {
+ const positive = (raw: string | undefined, fallback: number, max: number) => {
const value = Number(raw);
- return Number.isInteger(value) && value > 0 ? value : fallback;
+ return Number.isInteger(value) && value > 0 ? Math.min(value, max) : fallback;
};
return {
- batchLines: positive(env.OMB_EVENT_LOG_BATCH_LINES, EVENT_LOG_DEFAULTS.batchLines),
- queueEvents: positive(env.OMB_EVENT_LOG_QUEUE_EVENTS, EVENT_LOG_DEFAULTS.queueEvents),
- queueBytes: positive(env.OMB_EVENT_LOG_QUEUE_BYTES, EVENT_LOG_DEFAULTS.queueBytes),
- drainThreads: positive(env.OMB_EVENT_LOG_DRAIN_THREADS, EVENT_LOG_DEFAULTS.drainThreads),
+ batchLines: positive(env.OMB_EVENT_LOG_BATCH_LINES, EVENT_LOG_DEFAULTS.batchLines, EVENT_LOG_MAX.batchLines),
+ queueEvents: positive(env.OMB_EVENT_LOG_QUEUE_EVENTS, EVENT_LOG_DEFAULTS.queueEvents, EVENT_LOG_MAX.queueEvents),
+ queueBytes: positive(env.OMB_EVENT_LOG_QUEUE_BYTES, EVENT_LOG_DEFAULTS.queueBytes, EVENT_LOG_MAX.queueBytes),
+ drainThreads: positive(env.OMB_EVENT_LOG_DRAIN_THREADS, EVENT_LOG_DEFAULTS.drainThreads, EVENT_LOG_MAX.drainThreads),
};
}
@@ -110,10 +112,10 @@ export class EventBus {
this.gate = gate;
// A batch or worker count below one would leave drain() unable to empty the queue.
this.limits = {
- batchLines: Math.max(1, Math.floor(limits.batchLines) || 1),
- queueEvents: Math.max(1, Math.floor(limits.queueEvents) || 1),
- queueBytes: Math.max(1, Math.floor(limits.queueBytes) || 1),
- drainThreads: Math.max(1, Math.floor(limits.drainThreads) || 1),
+ batchLines: Math.min(EVENT_LOG_MAX.batchLines, Math.max(1, Math.floor(limits.batchLines) || 1)),
+ queueEvents: Math.min(EVENT_LOG_MAX.queueEvents, Math.max(1, Math.floor(limits.queueEvents) || 1)),
+ queueBytes: Math.min(EVENT_LOG_MAX.queueBytes, Math.max(1, Math.floor(limits.queueBytes) || 1)),
+ drainThreads: Math.min(EVENT_LOG_MAX.drainThreads, Math.max(1, Math.floor(limits.drainThreads) || 1)),
};
}
diff --git a/server/routes/status.ts b/server/routes/status.ts
index 5beebe2893..70af10e6c4 100644
--- a/server/routes/status.ts
+++ b/server/routes/status.ts
@@ -6,6 +6,7 @@ import { DATA_DIR, EVENTS_DIR, NATIVE_DIR, instanceConfigs, type AppConfig } fro
import { boundRetentionDays, decisionsCsv, readDecisionRange, readDecisions, type DecisionRow } from "../decision-log.ts";
import { doctorSummary } from "../doctor/start.ts";
import { flushNativeLog } from "../drivers/native.ts";
+import type { EventLogDrops } from "../harness/bus.ts";
import { editionForMembers, editionStatus, entitled } from "../enterprise.ts";
import { reportableServerVersion } from "../environment.ts";
import { fleetAvailable, fleetRequest, fleetSocketPath } from "../fleet-client.ts";
@@ -39,7 +40,7 @@ export interface StatusRouteDeps {
/** Whether bots run in the bot box: the MausBot connector reads it on a server its owner runs, on or off and nothing more. */
boxOn?(): boolean;
/** Canonical-log events dropped because its queue was full since this server started. */
- eventLogDrops?(): { events: number; bytes: number };
+ eventLogDrops?(): EventLogDrops;
}