From aba29fdd58b61bfae98dae643ceb4f16d78b06dc Mon Sep 17 00:00:00 2001 From: Noah Lindner Date: Tue, 8 Sep 2026 16:34:56 -0400 Subject: [PATCH] A response takes at most eight threads, direct first, and schedules the rest Co-Authored-By: Claude Fable 5.1 --- src/scheduler.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/scheduler.ts b/src/scheduler.ts index b9e06bc..cf49304 100644 --- a/src/scheduler.ts +++ b/src/scheduler.ts @@ -4,7 +4,7 @@ import { SocketModeClient } from "@slack/socket-mode"; import type { MessageEvent } from "@slack/types"; import type { MessageElement } from "@slack/web-api/dist/types/response/ConversationsRepliesResponse"; import { WebClient } from "@slack/web-api"; -import { and, asc, eq, gt, isNull, or } from "drizzle-orm"; +import { and, asc, desc, eq, gt, isNull, or } from "drizzle-orm"; import { inject, instanceCachingFactory, registry, singleton } from "tsyringe"; import { Codex } from "./codex"; import { Debounced } from "./debounce"; @@ -17,6 +17,8 @@ import { BOT_USER_ID, requireEnv, WORKSPACE } from "./tokens"; import { Voice } from "./voice"; import "./tools"; +const BATCH = 8; + const HEARD_SUBTYPES = new Set([ undefined, "bot_message", @@ -95,7 +97,9 @@ export class Scheduler { } private async respond(): Promise { - const convos = this.db.query.conversations.findMany().sync(); + const convos = this.db.query.conversations + .findMany({ orderBy: [desc(conversations.direct), asc(conversations.since)], limit: BATCH }) + .sync(); const settled = this.db.query.tasks .findMany({ where: and( @@ -114,6 +118,7 @@ export class Scheduler { await this.codex.respond(prompt); this.voice.close(direct); this.tick(); + if (this.ledger.wantsResponse()) this.respondSoon(); } private async listenToNoise(): Promise {