mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-12 07:20:45 +00:00
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:
@@ -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',
|
||||
|
||||
@@ -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 =
|
||||
|
||||
15
src/infra/outbound/abort.ts
Normal file
15
src/infra/outbound/abort.ts
Normal 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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user