refactor: consolidate throwIfAborted + fix isCompactionFailureError (#12463)

* refactor: consolidate throwIfAborted in outbound module

- Create abort.ts with shared throwIfAborted helper

- Update deliver.ts, message-action-runner.ts, outbound-send-service.ts

* fix: handle context overflow in isCompactionFailureError without requiring colon
This commit is contained in:
max
2026-02-09 00:32:57 -08:00
committed by GitHub
parent f0924d3c4e
commit 79c2466662
6 changed files with 27 additions and 29 deletions

View File

@@ -157,7 +157,7 @@ def find_duplicate_functions(files: List[Tuple[Path, int]], root_dir: Path) -> D
def main():
parser = argparse.ArgumentParser(
description='List the longest and shortest code files in a project'
description='Analyze code files: list longest/shortest files, find duplicate function names'
)
parser.add_argument(
'-t', '--threshold',

View File

@@ -50,16 +50,18 @@ export function isCompactionFailureError(errorMessage?: string): boolean {
if (!errorMessage) {
return false;
}
if (!isContextOverflowError(errorMessage)) {
return false;
}
const lower = errorMessage.toLowerCase();
return (
const hasCompactionTerm =
lower.includes("summarization failed") ||
lower.includes("auto-compaction") ||
lower.includes("compaction failed") ||
lower.includes("compaction")
);
lower.includes("compaction");
if (!hasCompactionTerm) {
return false;
}
// For compaction failures, also accept "context overflow" without colon
// since the error message itself describes a compaction/summarization failure
return isContextOverflowError(errorMessage) || lower.includes("context overflow");
}
const ERROR_PAYLOAD_PREFIX_RE =

View File

@@ -0,0 +1,15 @@
/**
* Utility for checking AbortSignal state and throwing a standard AbortError.
*/
/**
* Throws an AbortError if the given signal has been aborted.
* Use at async checkpoints to support cancellation.
*/
export function throwIfAborted(abortSignal?: AbortSignal): void {
if (abortSignal?.aborted) {
const err = new Error("Operation aborted");
err.name = "AbortError";
throw err;
}
}

View File

@@ -23,6 +23,7 @@ import {
} from "../../config/sessions.js";
import { markdownToSignalTextChunks, type SignalTextStyleRange } from "../../signal/format.js";
import { sendMessageSignal } from "../../signal/send.js";
import { throwIfAborted } from "./abort.js";
import { normalizeReplyPayloadsForDelivery } from "./payloads.js";
export type { NormalizedOutboundPayload } from "./payloads.js";
@@ -74,12 +75,6 @@ type ChannelHandler = {
sendMedia: (caption: string, mediaUrl: string) => Promise<OutboundDeliveryResult>;
};
function throwIfAborted(abortSignal?: AbortSignal): void {
if (abortSignal?.aborted) {
throw new Error("Outbound delivery aborted");
}
}
// Channel docking: outbound delivery delegates to plugin.outbound adapters.
async function createChannelHandler(params: {
cfg: OpenClawConfig;

View File

@@ -28,6 +28,7 @@ import {
type GatewayClientName,
} from "../../utils/message-channel.js";
import { loadWebMedia } from "../../web/media.js";
import { throwIfAborted } from "./abort.js";
import {
listConfiguredMessageChannels,
resolveMessageChannelSelection,
@@ -720,14 +721,6 @@ async function handleBroadcastAction(
};
}
function throwIfAborted(abortSignal?: AbortSignal): void {
if (abortSignal?.aborted) {
const err = new Error("Message send aborted");
err.name = "AbortError";
throw err;
}
}
async function handleSendAction(ctx: ResolvedActionContext): Promise<MessageActionRunResult> {
const {
cfg,

View File

@@ -6,6 +6,7 @@ import type { OutboundSendDeps } from "./deliver.js";
import type { MessagePollResult, MessageSendResult } from "./message.js";
import { dispatchChannelMessageAction } from "../../channels/plugins/message-actions.js";
import { appendAssistantMessageToSessionTranscript } from "../../config/sessions.js";
import { throwIfAborted } from "./abort.js";
import { sendMessage, sendPoll } from "./message.js";
export type OutboundGatewayContext = {
@@ -59,14 +60,6 @@ function extractToolPayload(result: AgentToolResult<unknown>): unknown {
return result.content ?? result;
}
function throwIfAborted(abortSignal?: AbortSignal): void {
if (abortSignal?.aborted) {
const err = new Error("Message send aborted");
err.name = "AbortError";
throw err;
}
}
export async function executeSendAction(params: {
ctx: OutboundSendContext;
to: string;