From 8b73d46585e82c4e080bf44239b4646fb540ac2a Mon Sep 17 00:00:00 2001 From: sh-agents <350651734+sh-agents@users.noreply.github.com> Date: Thu, 12 Nov 2026 07:02:56 +0000 Subject: [PATCH] support bot: set the core queue size --- apps/simplex-support-bot/README.md | 1 + apps/simplex-support-bot/bot.test.ts | 17 +++++++++++++++++ apps/simplex-support-bot/src/config.ts | 14 ++++++++++++++ apps/simplex-support-bot/src/index.ts | 2 +- scripts/support-bot/config/config.toml.example | 2 ++ 5 files changed, 35 insertions(+), 1 deletion(-) diff --git a/apps/simplex-support-bot/README.md b/apps/simplex-support-bot/README.md index a105aa5718..6274590c69 100644 --- a/apps/simplex-support-bot/README.md +++ b/apps/simplex-support-bot/README.md @@ -56,6 +56,7 @@ Run `npm start -- --help` for the auto-generated reference. Summary: | `--timezone` | both | no | `UTC` | IANA zone for weekend detection | | `--complete-hours` | both | no | `3` | auto-complete chats after N hours idle (`0` disables) | | `--card-flush-seconds` | both | no | `300` | debounce card state writes | +| `--queue-size` | both | no | core default, `1024` | internal queue size of the chat core, as the CLI's `-q`/`--queue-size` | | `--context-file` | both | required with a Grok API key | | text file with Grok system context | | `--dry-run` | both | no | | check config, database and state, then exit | | `--allow-migrations` | both | no | | with `--dry-run`: apply pending migrations instead of reporting them | diff --git a/apps/simplex-support-bot/bot.test.ts b/apps/simplex-support-bot/bot.test.ts index c24f0e0790..6cfe2fa75a 100644 --- a/apps/simplex-support-bot/bot.test.ts +++ b/apps/simplex-support-bot/bot.test.ts @@ -2484,6 +2484,21 @@ describe("parseConfig Validation", () => { .toThrow(/--allow-migrations requires --dry-run/) }) + test("--queue-size is unset by default, so the core default applies", () => { + expect(parseConfig(baseArgs).queueSize).toBeUndefined() + }) + + test("--queue-size parses a positive integer", () => { + expect(parseConfig([...baseArgs, "--queue-size", "65536"]).queueSize).toBe(65536) + }) + + test("--queue-size 0 or non-numeric → throws, as the core rejects 0", () => { + expect(() => parseConfig([...baseArgs, "--queue-size", "0"])) + .toThrow(/--queue-size must be a positive integer, got "0"/) + expect(() => parseConfig([...baseArgs, "--queue-size", "big"])) + .toThrow(/--queue-size must be a positive integer, got "big"/) + }) + test("--allow-down-migrations defaults to false, parses with --dry-run, throws without it", () => { expect(parseConfig(baseArgs).allowDownMigrations).toBe(false) expect(parseConfig([...baseArgs, "--dry-run", "--allow-down-migrations"]).allowDownMigrations).toBe(true) @@ -2503,6 +2518,7 @@ describe("parseConfig Validation", () => { `team_group = "SimpleX Support Team"`, `auto_add_team_members = ["1:Alice", "2:Bob"]`, `complete_hours = 0`, + `queue_size = 65536`, `db = "postgres"`, `pg_conn = "postgres://localhost/db"`, `[messages]`, @@ -2516,6 +2532,7 @@ describe("parseConfig Validation", () => { expect(cfg.teamGroup).toEqual({id: 0, name: "SimpleX Support Team"}) expect(cfg.teamMembers).toEqual([{id: 1, name: "Alice"}, {id: 2, name: "Bob"}]) expect(cfg.completeHours).toBe(0) + expect(cfg.queueSize).toBe(65536) expect(cfg.db).toEqual({type: "postgres", connectionString: "postgres://localhost/db"}) expect(cfg.messages.welcome).toBe("Hello!\n\nAsk anything.") expect(cfg.messages.teamAddedGrok).toBe("Grok helps.") diff --git a/apps/simplex-support-bot/src/config.ts b/apps/simplex-support-bot/src/config.ts index d268b71c54..899113f822 100644 --- a/apps/simplex-support-bot/src/config.ts +++ b/apps/simplex-support-bot/src/config.ts @@ -18,6 +18,7 @@ export interface Config { timezone: string completeHours: number cardFlushSeconds: number + queueSize: number | undefined contextFile: string | null dryRun: boolean allowMigrations: boolean @@ -44,6 +45,16 @@ function parseNonNegativeInt(flag: string) { } } +function parsePositiveInt(flag: string) { + return (raw: string): number => { + const n = parseInt(raw, 10) + if (!Number.isFinite(n) || n < 1) { + throw new Error(`${flag} must be a positive integer, got "${raw}"`) + } + return n + } +} + function buildCommand(): Command { return new Command() .name("simplex-chat-support-bot") @@ -60,6 +71,7 @@ function buildCommand(): Command { .option("--timezone ", "IANA timezone for weekend detection", "UTC") .option("--complete-hours ", "auto-complete chats after N hours idle (0 disables)", parseNonNegativeInt("--complete-hours"), 3) .option("--card-flush-seconds ", "debounce card state writes", parseNonNegativeInt("--card-flush-seconds"), 300) + .option("--queue-size ", "internal queue size of the chat core, as the CLI's --queue-size (core default: 1024)", parsePositiveInt("--queue-size")) .option("--context-file ", "text file with Grok system context (required with a Grok API key)") .option("--dry-run", "check config, database and state, then exit without starting chat") .option("--allow-migrations", "with --dry-run: apply pending migrations instead of reporting them") @@ -79,6 +91,7 @@ interface RawOpts { timezone: string completeHours: number cardFlushSeconds: number + queueSize?: number contextFile?: string dryRun?: boolean allowMigrations?: boolean @@ -196,6 +209,7 @@ export function parseConfig(args: string[]): Config { timezone: opts.timezone, completeHours: opts.completeHours, cardFlushSeconds: opts.cardFlushSeconds, + queueSize: opts.queueSize, contextFile, dryRun: opts.dryRun ?? false, allowMigrations: opts.allowMigrations ?? false, diff --git a/apps/simplex-support-bot/src/index.ts b/apps/simplex-support-bot/src/index.ts index aab7f5f604..2bb8ccec9f 100644 --- a/apps/simplex-support-bot/src/index.ts +++ b/apps/simplex-support-bot/src/index.ts @@ -95,7 +95,7 @@ async function main(): Promise { log("Initializing main bot...") const [chat, mainUser, mainAddress] = await bot.run({ profile: {displayName: "Ask SimpleX Team", fullName: "", image: supportImage}, - dbOpts: config.db, + dbOpts: {...config.db, queueSize: config.queueSize}, options: { addressSettings: { businessAddress: true, diff --git a/scripts/support-bot/config/config.toml.example b/scripts/support-bot/config/config.toml.example index fe05f6d7ad..a78d9c93b6 100644 --- a/scripts/support-bot/config/config.toml.example +++ b/scripts/support-bot/config/config.toml.example @@ -9,6 +9,8 @@ pg_conn = "postgres://simplex@127.0.0.1/simplex_support_bot" # Enables Grok replies; GROK_API_KEY takes precedence. # grok_api_key = "xai-..." timezone = "UTC" +# Internal queue size of the chat core, as the CLI's --queue-size; default 1024. +# queue_size = 65536 # A message left out keeps its built-in text. # {hours} is 24 on weekdays and 48 at weekends in the timezone above.