mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 23:14:31 +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():
|
def main():
|
||||||
parser = argparse.ArgumentParser(
|
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(
|
parser.add_argument(
|
||||||
'-t', '--threshold',
|
'-t', '--threshold',
|
||||||
|
|||||||
@@ -50,16 +50,18 @@ export function isCompactionFailureError(errorMessage?: string): boolean {
|
|||||||
if (!errorMessage) {
|
if (!errorMessage) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!isContextOverflowError(errorMessage)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
const lower = errorMessage.toLowerCase();
|
const lower = errorMessage.toLowerCase();
|
||||||
return (
|
const hasCompactionTerm =
|
||||||
lower.includes("summarization failed") ||
|
lower.includes("summarization failed") ||
|
||||||
lower.includes("auto-compaction") ||
|
lower.includes("auto-compaction") ||
|
||||||
lower.includes("compaction failed") ||
|
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 =
|
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";
|
} from "../../config/sessions.js";
|
||||||
import { markdownToSignalTextChunks, type SignalTextStyleRange } from "../../signal/format.js";
|
import { markdownToSignalTextChunks, type SignalTextStyleRange } from "../../signal/format.js";
|
||||||
import { sendMessageSignal } from "../../signal/send.js";
|
import { sendMessageSignal } from "../../signal/send.js";
|
||||||
|
import { throwIfAborted } from "./abort.js";
|
||||||
import { normalizeReplyPayloadsForDelivery } from "./payloads.js";
|
import { normalizeReplyPayloadsForDelivery } from "./payloads.js";
|
||||||
|
|
||||||
export type { NormalizedOutboundPayload } from "./payloads.js";
|
export type { NormalizedOutboundPayload } from "./payloads.js";
|
||||||
@@ -74,12 +75,6 @@ type ChannelHandler = {
|
|||||||
sendMedia: (caption: string, mediaUrl: string) => Promise<OutboundDeliveryResult>;
|
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.
|
// Channel docking: outbound delivery delegates to plugin.outbound adapters.
|
||||||
async function createChannelHandler(params: {
|
async function createChannelHandler(params: {
|
||||||
cfg: OpenClawConfig;
|
cfg: OpenClawConfig;
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import {
|
|||||||
type GatewayClientName,
|
type GatewayClientName,
|
||||||
} from "../../utils/message-channel.js";
|
} from "../../utils/message-channel.js";
|
||||||
import { loadWebMedia } from "../../web/media.js";
|
import { loadWebMedia } from "../../web/media.js";
|
||||||
|
import { throwIfAborted } from "./abort.js";
|
||||||
import {
|
import {
|
||||||
listConfiguredMessageChannels,
|
listConfiguredMessageChannels,
|
||||||
resolveMessageChannelSelection,
|
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> {
|
async function handleSendAction(ctx: ResolvedActionContext): Promise<MessageActionRunResult> {
|
||||||
const {
|
const {
|
||||||
cfg,
|
cfg,
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import type { OutboundSendDeps } from "./deliver.js";
|
|||||||
import type { MessagePollResult, MessageSendResult } from "./message.js";
|
import type { MessagePollResult, MessageSendResult } from "./message.js";
|
||||||
import { dispatchChannelMessageAction } from "../../channels/plugins/message-actions.js";
|
import { dispatchChannelMessageAction } from "../../channels/plugins/message-actions.js";
|
||||||
import { appendAssistantMessageToSessionTranscript } from "../../config/sessions.js";
|
import { appendAssistantMessageToSessionTranscript } from "../../config/sessions.js";
|
||||||
|
import { throwIfAborted } from "./abort.js";
|
||||||
import { sendMessage, sendPoll } from "./message.js";
|
import { sendMessage, sendPoll } from "./message.js";
|
||||||
|
|
||||||
export type OutboundGatewayContext = {
|
export type OutboundGatewayContext = {
|
||||||
@@ -59,14 +60,6 @@ function extractToolPayload(result: AgentToolResult<unknown>): unknown {
|
|||||||
return result.content ?? result;
|
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: {
|
export async function executeSendAction(params: {
|
||||||
ctx: OutboundSendContext;
|
ctx: OutboundSendContext;
|
||||||
to: string;
|
to: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user