fix: unblock control commands during active runs
This commit is contained in:
@@ -45,6 +45,7 @@
|
|||||||
- Sandbox: preserve configured PATH for `docker exec` so custom tools remain available. (#873) — thanks @akonyer.
|
- Sandbox: preserve configured PATH for `docker exec` so custom tools remain available. (#873) — thanks @akonyer.
|
||||||
- Slack: respect `channels.slack.requireMention` default when resolving channel mention gating. (#850) — thanks @evalexpr.
|
- Slack: respect `channels.slack.requireMention` default when resolving channel mention gating. (#850) — thanks @evalexpr.
|
||||||
- Telegram: aggregate split inbound messages into one prompt (reduces “one reply per fragment”).
|
- Telegram: aggregate split inbound messages into one prompt (reduces “one reply per fragment”).
|
||||||
|
- Telegram: let control commands bypass per-chat sequentialization; always allow abort triggers.
|
||||||
- Auto-reply: treat trailing `NO_REPLY` tokens as silent replies.
|
- Auto-reply: treat trailing `NO_REPLY` tokens as silent replies.
|
||||||
- Config: prevent partial config writes from clobbering unrelated settings (base hash guard + merge patch for connection saves).
|
- Config: prevent partial config writes from clobbering unrelated settings (base hash guard + merge patch for connection saves).
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ Compaction **summarizes older conversation** into a compact summary entry and ke
|
|||||||
Compaction **persists** in the session’s JSONL history.
|
Compaction **persists** in the session’s JSONL history.
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
See [Compaction config & modes](/compaction) for the `agents.defaults.compaction` settings.
|
See [Compaction config & modes](/concepts/compaction) for the `agents.defaults.compaction` settings.
|
||||||
|
|
||||||
## Auto-compaction (default on)
|
## Auto-compaction (default on)
|
||||||
When a session nears or exceeds the model’s context window, Clawdbot triggers auto-compaction and may retry the original request using the compacted context.
|
When a session nears or exceeds the model’s context window, Clawdbot triggers auto-compaction and may retry the original request using the compacted context.
|
||||||
|
|||||||
@@ -1541,7 +1541,7 @@ See [/concepts/session-pruning](/concepts/session-pruning) for behavior details.
|
|||||||
|
|
||||||
#### `agents.defaults.compaction` (reserve headroom + memory flush)
|
#### `agents.defaults.compaction` (reserve headroom + memory flush)
|
||||||
|
|
||||||
`agents.defaults.compaction.mode` selects the compaction summarization strategy. Defaults to `default`; set `safeguard` to enable chunked summarization for very long histories. See [/compaction](/compaction).
|
`agents.defaults.compaction.mode` selects the compaction summarization strategy. Defaults to `default`; set `safeguard` to enable chunked summarization for very long histories. See [/concepts/compaction](/concepts/compaction).
|
||||||
|
|
||||||
`agents.defaults.compaction.reserveTokensFloor` enforces a minimum `reserveTokens`
|
`agents.defaults.compaction.reserveTokensFloor` enforces a minimum `reserveTokens`
|
||||||
value for Pi compaction (default: `20000`). Set it to `0` to disable the floor.
|
value for Pi compaction (default: `20000`). Set it to `0` to disable the floor.
|
||||||
|
|||||||
@@ -1412,6 +1412,7 @@ abort
|
|||||||
esc
|
esc
|
||||||
wait
|
wait
|
||||||
exit
|
exit
|
||||||
|
interrupt
|
||||||
```
|
```
|
||||||
|
|
||||||
These are abort triggers (not slash commands).
|
These are abort triggers (not slash commands).
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ Notes:
|
|||||||
- Re-sending with the same `idempotencyKey` returns `{ status: "in_flight" }` while running, and `{ status: "ok" }` after completion.
|
- Re-sending with the same `idempotencyKey` returns `{ status: "in_flight" }` while running, and `{ status: "ok" }` after completion.
|
||||||
- Stop:
|
- Stop:
|
||||||
- Click **Stop** (calls `chat.abort`)
|
- Click **Stop** (calls `chat.abort`)
|
||||||
- Type `/stop` (or `stop|esc|abort|wait|exit`) to abort out-of-band
|
- Type `/stop` (or `stop|esc|abort|wait|exit|interrupt`) to abort out-of-band
|
||||||
- `chat.abort` supports `{ sessionKey }` (no `runId`) to abort all active runs for that session
|
- `chat.abort` supports `{ sessionKey }` (no `runId`) to abort all active runs for that session
|
||||||
|
|
||||||
## Tailnet access (recommended)
|
## Tailnet access (recommended)
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import {
|
|||||||
listChatCommandsForConfig,
|
listChatCommandsForConfig,
|
||||||
normalizeCommandBody,
|
normalizeCommandBody,
|
||||||
} from "./commands-registry.js";
|
} from "./commands-registry.js";
|
||||||
|
import { isAbortTrigger } from "./reply/abort.js";
|
||||||
|
|
||||||
export function hasControlCommand(
|
export function hasControlCommand(
|
||||||
text?: string,
|
text?: string,
|
||||||
@@ -31,3 +32,16 @@ export function hasControlCommand(
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isControlCommandMessage(
|
||||||
|
text?: string,
|
||||||
|
cfg?: ClawdbotConfig,
|
||||||
|
options?: CommandNormalizeOptions,
|
||||||
|
): boolean {
|
||||||
|
if (!text) return false;
|
||||||
|
const trimmed = text.trim();
|
||||||
|
if (!trimmed) return false;
|
||||||
|
if (hasControlCommand(trimmed, cfg, options)) return true;
|
||||||
|
const normalized = normalizeCommandBody(trimmed, options).trim().toLowerCase();
|
||||||
|
return isAbortTrigger(normalized);
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import os from "node:os";
|
|||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import { describe, expect, it } from "vitest";
|
import { describe, expect, it } from "vitest";
|
||||||
import type { ClawdbotConfig } from "../../config/config.js";
|
import type { ClawdbotConfig } from "../../config/config.js";
|
||||||
import { isAbortTrigger } from "./abort.js";
|
import { isAbortTrigger, tryFastAbortFromMessage } from "./abort.js";
|
||||||
import { initSessionState } from "./session.js";
|
import { initSessionState } from "./session.js";
|
||||||
|
|
||||||
describe("abort detection", () => {
|
describe("abort detection", () => {
|
||||||
@@ -35,8 +35,30 @@ describe("abort detection", () => {
|
|||||||
expect(isAbortTrigger("abort")).toBe(true);
|
expect(isAbortTrigger("abort")).toBe(true);
|
||||||
expect(isAbortTrigger("wait")).toBe(true);
|
expect(isAbortTrigger("wait")).toBe(true);
|
||||||
expect(isAbortTrigger("exit")).toBe(true);
|
expect(isAbortTrigger("exit")).toBe(true);
|
||||||
|
expect(isAbortTrigger("interrupt")).toBe(true);
|
||||||
expect(isAbortTrigger("hello")).toBe(false);
|
expect(isAbortTrigger("hello")).toBe(false);
|
||||||
// /stop is NOT matched by isAbortTrigger - it's handled separately
|
// /stop is NOT matched by isAbortTrigger - it's handled separately
|
||||||
expect(isAbortTrigger("/stop")).toBe(false);
|
expect(isAbortTrigger("/stop")).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("fast-aborts even when text commands are disabled", async () => {
|
||||||
|
const root = await fs.mkdtemp(path.join(os.tmpdir(), "clawdbot-abort-"));
|
||||||
|
const storePath = path.join(root, "sessions.json");
|
||||||
|
const cfg = { session: { store: storePath }, commands: { text: false } } as ClawdbotConfig;
|
||||||
|
|
||||||
|
const result = await tryFastAbortFromMessage({
|
||||||
|
ctx: {
|
||||||
|
CommandBody: "/stop",
|
||||||
|
RawBody: "/stop",
|
||||||
|
SessionKey: "telegram:123",
|
||||||
|
Provider: "telegram",
|
||||||
|
Surface: "telegram",
|
||||||
|
From: "telegram:123",
|
||||||
|
To: "telegram:123",
|
||||||
|
},
|
||||||
|
cfg,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(result.handled).toBe(true);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -9,11 +9,11 @@ import {
|
|||||||
} from "../../config/sessions.js";
|
} from "../../config/sessions.js";
|
||||||
import { parseAgentSessionKey } from "../../routing/session-key.js";
|
import { parseAgentSessionKey } from "../../routing/session-key.js";
|
||||||
import { resolveCommandAuthorization } from "../command-auth.js";
|
import { resolveCommandAuthorization } from "../command-auth.js";
|
||||||
import { normalizeCommandBody, shouldHandleTextCommands } from "../commands-registry.js";
|
import { normalizeCommandBody } from "../commands-registry.js";
|
||||||
import type { MsgContext } from "../templating.js";
|
import type { MsgContext } from "../templating.js";
|
||||||
import { stripMentions, stripStructuralPrefixes } from "./mentions.js";
|
import { stripMentions, stripStructuralPrefixes } from "./mentions.js";
|
||||||
|
|
||||||
const ABORT_TRIGGERS = new Set(["stop", "esc", "abort", "wait", "exit"]);
|
const ABORT_TRIGGERS = new Set(["stop", "esc", "abort", "wait", "exit", "interrupt"]);
|
||||||
const ABORT_MEMORY = new Map<string, boolean>();
|
const ABORT_MEMORY = new Map<string, boolean>();
|
||||||
|
|
||||||
export function isAbortTrigger(text?: string): boolean {
|
export function isAbortTrigger(text?: string): boolean {
|
||||||
@@ -57,14 +57,6 @@ export async function tryFastAbortFromMessage(params: {
|
|||||||
cfg: ClawdbotConfig;
|
cfg: ClawdbotConfig;
|
||||||
}): Promise<{ handled: boolean; aborted: boolean }> {
|
}): Promise<{ handled: boolean; aborted: boolean }> {
|
||||||
const { ctx, cfg } = params;
|
const { ctx, cfg } = params;
|
||||||
const surface = (ctx.Surface ?? ctx.Provider ?? "").trim().toLowerCase();
|
|
||||||
const allowTextCommands = shouldHandleTextCommands({
|
|
||||||
cfg,
|
|
||||||
surface,
|
|
||||||
commandSource: ctx.CommandSource,
|
|
||||||
});
|
|
||||||
if (!allowTextCommands) return { handled: false, aborted: false };
|
|
||||||
|
|
||||||
const commandAuthorized = ctx.CommandAuthorized ?? true;
|
const commandAuthorized = ctx.CommandAuthorized ?? true;
|
||||||
const auth = resolveCommandAuthorization({
|
const auth = resolveCommandAuthorization({
|
||||||
ctx,
|
ctx,
|
||||||
|
|||||||
@@ -251,6 +251,21 @@ describe("createTelegramBot", () => {
|
|||||||
update: { message: { chat: { id: 555 } } },
|
update: { message: { chat: { id: 555 } } },
|
||||||
}),
|
}),
|
||||||
).toBe("telegram:555");
|
).toBe("telegram:555");
|
||||||
|
expect(
|
||||||
|
getTelegramSequentialKey({
|
||||||
|
message: { chat: { id: 123 }, text: "/stop" },
|
||||||
|
}),
|
||||||
|
).toBe("telegram:123:control");
|
||||||
|
expect(
|
||||||
|
getTelegramSequentialKey({
|
||||||
|
message: { chat: { id: 123 }, text: "/status" },
|
||||||
|
}),
|
||||||
|
).toBe("telegram:123:control");
|
||||||
|
expect(
|
||||||
|
getTelegramSequentialKey({
|
||||||
|
message: { chat: { id: 123 }, text: "stop" },
|
||||||
|
}),
|
||||||
|
).toBe("telegram:123:control");
|
||||||
});
|
});
|
||||||
it("routes callback_query payloads as messages and answers callbacks", async () => {
|
it("routes callback_query payloads as messages and answers callbacks", async () => {
|
||||||
onSpy.mockReset();
|
onSpy.mockReset();
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { apiThrottler } from "@grammyjs/transformer-throttler";
|
|||||||
import type { ApiClientOptions } from "grammy";
|
import type { ApiClientOptions } from "grammy";
|
||||||
import { Bot, webhookCallback } from "grammy";
|
import { Bot, webhookCallback } from "grammy";
|
||||||
import { resolveDefaultAgentId } from "../agents/agent-scope.js";
|
import { resolveDefaultAgentId } from "../agents/agent-scope.js";
|
||||||
|
import { isControlCommandMessage } from "../auto-reply/command-detection.js";
|
||||||
import { resolveTextChunkLimit } from "../auto-reply/chunk.js";
|
import { resolveTextChunkLimit } from "../auto-reply/chunk.js";
|
||||||
import { DEFAULT_GROUP_HISTORY_LIMIT, type HistoryEntry } from "../auto-reply/reply/history.js";
|
import { DEFAULT_GROUP_HISTORY_LIMIT, type HistoryEntry } from "../auto-reply/reply/history.js";
|
||||||
import {
|
import {
|
||||||
@@ -66,6 +67,12 @@ export function getTelegramSequentialKey(ctx: {
|
|||||||
ctx.update?.edited_message ??
|
ctx.update?.edited_message ??
|
||||||
ctx.update?.callback_query?.message;
|
ctx.update?.callback_query?.message;
|
||||||
const chatId = msg?.chat?.id ?? ctx.chat?.id;
|
const chatId = msg?.chat?.id ?? ctx.chat?.id;
|
||||||
|
const rawText = msg?.text ?? msg?.caption;
|
||||||
|
const botUsername = (ctx as { me?: { username?: string } }).me?.username;
|
||||||
|
if (rawText && isControlCommandMessage(rawText, undefined, botUsername ? { botUsername } : undefined)) {
|
||||||
|
if (typeof chatId === "number") return `telegram:${chatId}:control`;
|
||||||
|
return "telegram:control";
|
||||||
|
}
|
||||||
const isForum = (msg?.chat as { is_forum?: boolean } | undefined)?.is_forum;
|
const isForum = (msg?.chat as { is_forum?: boolean } | undefined)?.is_forum;
|
||||||
const threadId = resolveTelegramForumThreadId({
|
const threadId = resolveTelegramForumThreadId({
|
||||||
isForum,
|
isForum,
|
||||||
|
|||||||
Reference in New Issue
Block a user