2026-02-21 15:42:47 -07:00
|
|
|
import type { OhMyOpenCodeConfig } from "../config";
|
2026-04-28 17:59:25 +09:00
|
|
|
import type { PluginInput } from "@opencode-ai/plugin";
|
2026-02-21 15:42:47 -07:00
|
|
|
import type { PluginContext } from "./types";
|
2026-02-08 16:25:25 +09:00
|
|
|
|
|
|
|
|
import {
|
|
|
|
|
clearSessionAgent,
|
|
|
|
|
getMainSessionID,
|
2026-02-19 04:41:00 +02:00
|
|
|
getSessionAgent,
|
2026-04-28 10:47:36 +09:00
|
|
|
resolveRegisteredAgentName,
|
2026-02-21 15:42:47 -07:00
|
|
|
setMainSession,
|
2026-02-19 04:41:00 +02:00
|
|
|
subagentSessions,
|
|
|
|
|
syncSubagentSessions,
|
2026-02-08 16:25:25 +09:00
|
|
|
updateSessionAgent,
|
2026-02-21 15:42:47 -07:00
|
|
|
} from "../features/claude-code-session-state";
|
|
|
|
|
import {
|
|
|
|
|
clearPendingModelFallback,
|
|
|
|
|
clearSessionFallbackChain,
|
2026-03-04 18:35:09 +01:00
|
|
|
setSessionFallbackChain,
|
2026-02-21 15:42:47 -07:00
|
|
|
setPendingModelFallback,
|
2026-04-18 02:35:46 +09:00
|
|
|
type ModelFallbackHook,
|
2026-02-21 15:42:47 -07:00
|
|
|
} from "../hooks/model-fallback/hook";
|
2026-03-18 14:21:27 +01:00
|
|
|
import { getRawFallbackModels } from "../hooks/runtime-fallback/fallback-models";
|
2026-03-29 04:53:36 +09:00
|
|
|
import {
|
|
|
|
|
clearBackgroundOutputConsumptionsForParentSession,
|
|
|
|
|
clearBackgroundOutputConsumptionsForTaskSession,
|
|
|
|
|
restoreBackgroundOutputConsumption,
|
|
|
|
|
} from "../shared/background-output-consumption";
|
2026-05-13 13:36:25 +09:00
|
|
|
import { createInternalAgentContinuationTextPart, resetMessageCursor } from "../shared";
|
2026-03-04 18:35:09 +01:00
|
|
|
import { getAgentConfigKey } from "../shared/agent-display-names";
|
2026-03-12 01:49:16 +09:00
|
|
|
import { readConnectedProvidersCache } from "../shared/connected-providers-cache";
|
2026-04-28 17:59:25 +09:00
|
|
|
import { invalidateContextWindowUsageCache } from "../shared/dynamic-truncator";
|
2026-02-21 15:42:47 -07:00
|
|
|
import { log } from "../shared/logger";
|
|
|
|
|
import { shouldRetryError } from "../shared/model-error-classifier";
|
2026-03-04 20:43:55 +01:00
|
|
|
import { buildFallbackChainFromModels } from "../shared/fallback-chain-from-models";
|
2026-03-04 20:52:15 +01:00
|
|
|
import { extractRetryAttempt, normalizeRetryStatusMessage } from "../shared/retry-status-utils";
|
2026-03-12 01:49:16 +09:00
|
|
|
import { clearSessionModel, getSessionModel, setSessionModel } from "../shared/session-model-state";
|
2026-03-18 14:21:27 +01:00
|
|
|
import { clearSessionPromptParams } from "../shared/session-prompt-params-state";
|
2026-02-21 15:42:47 -07:00
|
|
|
import { deleteSessionTools } from "../shared/session-tools-store";
|
|
|
|
|
import { lspManager } from "../tools";
|
2026-04-07 22:49:37 +09:00
|
|
|
import { dispatchOpenClawEvent } from "../openclaw/runtime-dispatch";
|
2026-04-28 10:47:36 +09:00
|
|
|
import { createTeamIdleWakeHint } from "../hooks/team-session-events/team-idle-wake-hint";
|
|
|
|
|
import { createTeamLeadOrphanHandler } from "../hooks/team-session-events/team-lead-orphan-handler";
|
|
|
|
|
import { createTeamMemberErrorHandler } from "../hooks/team-session-events/team-member-error-handler";
|
|
|
|
|
import { createTeamMemberStatusHandler } from "../hooks/team-session-events/team-member-status-handler";
|
2026-05-15 13:19:10 +09:00
|
|
|
import { promptAfterSessionIdle, promptAsyncAfterSessionIdle, releasePromptAsyncReservation } from "../hooks/shared/prompt-async-gate";
|
2026-02-21 15:42:47 -07:00
|
|
|
|
|
|
|
|
import type { CreatedHooks } from "../create-hooks";
|
|
|
|
|
import type { Managers } from "../create-managers";
|
|
|
|
|
import { pruneRecentSyntheticIdles } from "./recent-synthetic-idles";
|
|
|
|
|
import { normalizeSessionStatusToIdle } from "./session-status-normalizer";
|
2026-05-12 11:48:18 +09:00
|
|
|
import { resolveMessageEventSessionID, resolveSessionEventID } from "../shared/event-session-id";
|
2026-02-08 16:25:25 +09:00
|
|
|
|
|
|
|
|
type FirstMessageVariantGate = {
|
2026-02-21 15:42:47 -07:00
|
|
|
markSessionCreated: (sessionInfo: { id?: string; title?: string; parentID?: string } | undefined) => void;
|
|
|
|
|
clear: (sessionID: string) => void;
|
|
|
|
|
};
|
2026-02-08 16:25:25 +09:00
|
|
|
|
2026-05-15 11:06:04 +09:00
|
|
|
type FallbackContinuationDedupeKeys = {
|
|
|
|
|
modelKey?: string;
|
|
|
|
|
providerModelKey?: string;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
type FallbackContinuationDedupeState = {
|
|
|
|
|
modelKeys: Set<string>;
|
|
|
|
|
providerModelKeys: Set<string>;
|
|
|
|
|
providerlessModelKeys: Set<string>;
|
|
|
|
|
};
|
|
|
|
|
|
2026-05-15 11:45:21 +09:00
|
|
|
type FallbackContinuationContext = {
|
|
|
|
|
agentName?: string;
|
|
|
|
|
providerID?: string;
|
|
|
|
|
dedupeProviderID?: string;
|
|
|
|
|
modelID?: string;
|
|
|
|
|
};
|
|
|
|
|
|
2026-02-19 04:41:00 +02:00
|
|
|
function isRecord(value: unknown): value is Record<string, unknown> {
|
2026-02-21 15:42:47 -07:00
|
|
|
return typeof value === "object" && value !== null;
|
2026-02-19 04:41:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function normalizeFallbackModelID(modelID: string): string {
|
|
|
|
|
return modelID
|
|
|
|
|
.replace(/-thinking$/i, "")
|
|
|
|
|
.replace(/-max$/i, "")
|
2026-02-21 15:42:47 -07:00
|
|
|
.replace(/-high$/i, "");
|
2026-02-19 04:41:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function extractErrorName(error: unknown): string | undefined {
|
2026-02-21 15:42:47 -07:00
|
|
|
if (isRecord(error) && typeof error.name === "string") return error.name;
|
|
|
|
|
if (error instanceof Error) return error.name;
|
|
|
|
|
return undefined;
|
2026-02-19 04:41:00 +02:00
|
|
|
}
|
|
|
|
|
|
2026-04-28 15:29:33 +09:00
|
|
|
export function extractErrorMessage(error: unknown): string {
|
2026-02-21 15:42:47 -07:00
|
|
|
if (!error) return "";
|
|
|
|
|
if (typeof error === "string") return error;
|
2026-02-19 04:41:00 +02:00
|
|
|
|
|
|
|
|
if (isRecord(error)) {
|
|
|
|
|
const candidates: unknown[] = [
|
|
|
|
|
error.data,
|
|
|
|
|
isRecord(error.data) ? error.data.error : undefined,
|
2026-04-28 15:29:33 +09:00
|
|
|
error.error,
|
2026-02-19 04:41:00 +02:00
|
|
|
error.cause,
|
2026-04-28 15:29:33 +09:00
|
|
|
error,
|
2026-02-21 15:42:47 -07:00
|
|
|
];
|
2026-02-19 04:41:00 +02:00
|
|
|
|
|
|
|
|
for (const candidate of candidates) {
|
|
|
|
|
if (isRecord(candidate) && typeof candidate.message === "string" && candidate.message.length > 0) {
|
2026-02-21 15:42:47 -07:00
|
|
|
return candidate.message;
|
2026-02-19 04:41:00 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-28 15:29:33 +09:00
|
|
|
if (error instanceof Error) return error.message;
|
|
|
|
|
|
2026-02-19 04:41:00 +02:00
|
|
|
try {
|
2026-02-21 15:42:47 -07:00
|
|
|
return JSON.stringify(error);
|
2026-02-19 04:41:00 +02:00
|
|
|
} catch {
|
2026-02-21 15:42:47 -07:00
|
|
|
return String(error);
|
2026-02-19 04:41:00 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-21 15:42:47 -07:00
|
|
|
function extractProviderModelFromErrorMessage(message: string): { providerID?: string; modelID?: string } {
|
|
|
|
|
const lower = message.toLowerCase();
|
2026-02-19 04:41:00 +02:00
|
|
|
|
2026-02-21 15:42:47 -07:00
|
|
|
const providerModel = lower.match(/model\s+not\s+found:\s*([a-z0-9_-]+)\s*\/\s*([a-z0-9._-]+)/i);
|
2026-02-19 04:41:00 +02:00
|
|
|
if (providerModel) {
|
|
|
|
|
return {
|
|
|
|
|
providerID: providerModel[1],
|
|
|
|
|
modelID: providerModel[2],
|
2026-02-21 15:42:47 -07:00
|
|
|
};
|
2026-02-19 04:41:00 +02:00
|
|
|
}
|
|
|
|
|
|
2026-02-21 15:42:47 -07:00
|
|
|
const modelOnly = lower.match(/unknown\s+provider\s+for\s+model\s+([a-z0-9._-]+)/i);
|
2026-02-19 04:41:00 +02:00
|
|
|
if (modelOnly) {
|
|
|
|
|
return {
|
|
|
|
|
modelID: modelOnly[1],
|
2026-02-21 15:42:47 -07:00
|
|
|
};
|
2026-02-19 04:41:00 +02:00
|
|
|
}
|
|
|
|
|
|
2026-02-21 15:42:47 -07:00
|
|
|
return {};
|
2026-02-19 04:41:00 +02:00
|
|
|
}
|
2026-03-04 18:35:09 +01:00
|
|
|
function applyUserConfiguredFallbackChain(
|
2026-04-18 02:35:46 +09:00
|
|
|
modelFallback: Pick<ModelFallbackHook, "setSessionFallbackChain"> | null | undefined,
|
2026-03-04 18:35:09 +01:00
|
|
|
sessionID: string,
|
|
|
|
|
agentName: string,
|
|
|
|
|
currentProviderID: string,
|
|
|
|
|
pluginConfig: OhMyOpenCodeConfig,
|
|
|
|
|
): void {
|
|
|
|
|
const agentKey = getAgentConfigKey(agentName);
|
2026-03-18 14:21:27 +01:00
|
|
|
const rawFallbackModels = getRawFallbackModels(sessionID, agentKey, pluginConfig);
|
|
|
|
|
if (!rawFallbackModels || rawFallbackModels.length === 0) return;
|
2026-03-04 18:35:09 +01:00
|
|
|
|
2026-03-18 14:21:27 +01:00
|
|
|
const fallbackChain = buildFallbackChainFromModels(rawFallbackModels, currentProviderID);
|
2026-03-04 18:35:09 +01:00
|
|
|
|
2026-03-04 20:43:55 +01:00
|
|
|
if (fallbackChain && fallbackChain.length > 0) {
|
2026-04-18 02:35:46 +09:00
|
|
|
if (modelFallback) {
|
|
|
|
|
setSessionFallbackChain(modelFallback, sessionID, fallbackChain);
|
|
|
|
|
}
|
2026-03-04 18:35:09 +01:00
|
|
|
}
|
|
|
|
|
}
|
2026-03-07 15:39:25 +09:00
|
|
|
|
|
|
|
|
function isCompactionAgent(agent: string): boolean {
|
|
|
|
|
return agent.toLowerCase() === "compaction";
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-21 15:42:47 -07:00
|
|
|
type EventInput = Parameters<NonNullable<NonNullable<CreatedHooks["writeExistingFileGuard"]>["event"]>>[0];
|
2026-02-08 16:25:25 +09:00
|
|
|
export function createEventHandler(args: {
|
2026-02-21 15:42:47 -07:00
|
|
|
ctx: PluginContext;
|
|
|
|
|
pluginConfig: OhMyOpenCodeConfig;
|
|
|
|
|
firstMessageVariantGate: FirstMessageVariantGate;
|
|
|
|
|
managers: Managers;
|
|
|
|
|
hooks: CreatedHooks;
|
2026-02-21 02:45:48 +09:00
|
|
|
}): (input: EventInput) => Promise<void> {
|
2026-04-05 13:27:50 +09:00
|
|
|
const { ctx, pluginConfig, firstMessageVariantGate, managers, hooks } = args;
|
2026-04-11 22:14:48 +09:00
|
|
|
const tmuxIntegrationEnabled = pluginConfig.tmux?.enabled ?? false;
|
2026-04-28 16:41:32 +09:00
|
|
|
const pluginContext = ctx as PluginContext & {
|
2026-02-21 15:42:47 -07:00
|
|
|
directory: string;
|
2026-02-21 16:24:18 +09:00
|
|
|
client: {
|
|
|
|
|
session: {
|
2026-02-21 15:42:47 -07:00
|
|
|
abort: (input: { path: { id: string } }) => Promise<unknown>;
|
2026-03-04 18:35:09 +01:00
|
|
|
promptAsync?: (input: {
|
|
|
|
|
path: { id: string };
|
2026-04-28 10:47:36 +09:00
|
|
|
body: {
|
2026-05-13 13:36:25 +09:00
|
|
|
parts: Array<{
|
|
|
|
|
type: "text";
|
|
|
|
|
text: string;
|
|
|
|
|
synthetic?: boolean;
|
|
|
|
|
metadata?: Record<string, unknown>;
|
|
|
|
|
}>;
|
2026-04-28 10:47:36 +09:00
|
|
|
agent?: string;
|
|
|
|
|
model?: { providerID: string; modelID: string };
|
|
|
|
|
variant?: string;
|
|
|
|
|
};
|
2026-03-04 18:35:09 +01:00
|
|
|
query: { directory: string };
|
|
|
|
|
}) => Promise<unknown>;
|
2026-02-21 16:24:18 +09:00
|
|
|
prompt: (input: {
|
2026-02-21 15:42:47 -07:00
|
|
|
path: { id: string };
|
2026-04-28 10:47:36 +09:00
|
|
|
body: {
|
2026-05-13 13:36:25 +09:00
|
|
|
parts: Array<{
|
|
|
|
|
type: "text";
|
|
|
|
|
text: string;
|
|
|
|
|
synthetic?: boolean;
|
|
|
|
|
metadata?: Record<string, unknown>;
|
|
|
|
|
}>;
|
2026-04-28 10:47:36 +09:00
|
|
|
agent?: string;
|
|
|
|
|
model?: { providerID: string; modelID: string };
|
|
|
|
|
variant?: string;
|
|
|
|
|
};
|
2026-02-21 15:42:47 -07:00
|
|
|
query: { directory: string };
|
|
|
|
|
}) => Promise<unknown>;
|
2026-04-28 16:41:32 +09:00
|
|
|
summarize: {
|
|
|
|
|
(input: {
|
|
|
|
|
path: { id: string };
|
|
|
|
|
body: { providerID: string; modelID: string; auto?: boolean };
|
|
|
|
|
query: { directory: string };
|
|
|
|
|
}): Promise<unknown>;
|
|
|
|
|
(input: {
|
|
|
|
|
path: { id: string };
|
|
|
|
|
body: { auto: boolean };
|
|
|
|
|
query: { directory: string };
|
|
|
|
|
}): Promise<unknown>;
|
|
|
|
|
};
|
2026-02-21 15:42:47 -07:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
};
|
2026-02-21 16:24:18 +09:00
|
|
|
const isRuntimeFallbackEnabled =
|
|
|
|
|
hooks.runtimeFallback !== null &&
|
|
|
|
|
hooks.runtimeFallback !== undefined &&
|
2026-02-22 01:44:53 +09:00
|
|
|
(typeof args.pluginConfig.runtime_fallback === "boolean"
|
|
|
|
|
? args.pluginConfig.runtime_fallback
|
2026-02-21 15:42:47 -07:00
|
|
|
: (args.pluginConfig.runtime_fallback?.enabled ?? false));
|
2026-02-08 16:25:25 +09:00
|
|
|
|
2026-02-22 17:25:04 +09:00
|
|
|
const isModelFallbackEnabled =
|
|
|
|
|
hooks.modelFallback !== null && hooks.modelFallback !== undefined;
|
2026-04-18 02:35:46 +09:00
|
|
|
const modelFallback = hooks.modelFallback;
|
2026-02-22 17:25:04 +09:00
|
|
|
|
2026-02-19 04:41:00 +02:00
|
|
|
// Avoid triggering multiple abort+continue cycles for the same failing assistant message.
|
2026-02-21 15:42:47 -07:00
|
|
|
const lastHandledModelErrorMessageID = new Map<string, string>();
|
|
|
|
|
const lastHandledRetryStatusKey = new Map<string, string>();
|
|
|
|
|
const lastKnownModelBySession = new Map<string, { providerID: string; modelID: string }>();
|
2026-05-15 10:07:35 +09:00
|
|
|
const modelFallbackContinuationsInFlight = new Set<string>();
|
2026-05-15 11:06:04 +09:00
|
|
|
const lastDispatchedModelFallbackContinuationKeys = new Map<string, FallbackContinuationDedupeState>();
|
2026-02-19 04:41:00 +02:00
|
|
|
|
2026-03-12 01:49:16 +09:00
|
|
|
const resolveFallbackProviderID = (sessionID: string, providerHint?: string): string => {
|
2026-05-14 01:03:19 +09:00
|
|
|
const normalizedProviderHint = providerHint?.trim();
|
|
|
|
|
if (normalizedProviderHint) {
|
|
|
|
|
return normalizedProviderHint;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-12 01:49:16 +09:00
|
|
|
const sessionModel = getSessionModel(sessionID);
|
|
|
|
|
if (sessionModel?.providerID) {
|
|
|
|
|
return sessionModel.providerID;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const lastKnownModel = lastKnownModelBySession.get(sessionID);
|
|
|
|
|
if (lastKnownModel?.providerID) {
|
|
|
|
|
return lastKnownModel.providerID;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-12 11:05:31 +09:00
|
|
|
const connectedProvider = readConnectedProvidersCache()?.[0];
|
|
|
|
|
if (connectedProvider) {
|
|
|
|
|
return connectedProvider;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-12 01:49:16 +09:00
|
|
|
return "opencode";
|
|
|
|
|
};
|
|
|
|
|
|
2026-03-27 09:30:43 +01:00
|
|
|
const getEventSessionID = (input: EventInput): string | undefined => {
|
|
|
|
|
const properties = input.event.properties;
|
2026-05-12 11:48:18 +09:00
|
|
|
if (input.event.type.startsWith("session.")) {
|
|
|
|
|
return resolveSessionEventID(properties);
|
2026-03-27 09:30:43 +01:00
|
|
|
}
|
2026-05-12 11:48:18 +09:00
|
|
|
if (input.event.type.startsWith("message.") || input.event.type.startsWith("tool.")) {
|
|
|
|
|
return resolveMessageEventSessionID(properties);
|
|
|
|
|
}
|
|
|
|
|
const record: Record<string, unknown> | undefined = isRecord(properties) ? properties : undefined;
|
|
|
|
|
const sessionID = record?.sessionID;
|
|
|
|
|
return typeof sessionID === "string" && sessionID.length > 0 ? sessionID : undefined;
|
2026-03-27 09:30:43 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const runEventHookSafely = async (
|
|
|
|
|
hookName: string,
|
|
|
|
|
handler: ((input: EventInput) => unknown | Promise<unknown>) | null | undefined,
|
|
|
|
|
input: EventInput,
|
|
|
|
|
): Promise<void> => {
|
|
|
|
|
if (!handler) return;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
await Promise.resolve(handler(input));
|
|
|
|
|
} catch (error) {
|
|
|
|
|
log("[event] hook execution failed", {
|
|
|
|
|
hook: hookName,
|
|
|
|
|
eventType: input.event.type,
|
|
|
|
|
sessionID: getEventSessionID(input),
|
|
|
|
|
error,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2026-02-21 03:33:15 +09:00
|
|
|
const dispatchToHooks = async (input: EventInput): Promise<void> => {
|
2026-03-27 09:30:43 +01:00
|
|
|
await runEventHookSafely("autoUpdateChecker", hooks.autoUpdateChecker?.event, input);
|
|
|
|
|
await runEventHookSafely("legacyPluginToast", hooks.legacyPluginToast?.event, input);
|
|
|
|
|
await runEventHookSafely("claudeCodeHooks", hooks.claudeCodeHooks?.event, input);
|
|
|
|
|
await runEventHookSafely("backgroundNotificationHook", hooks.backgroundNotificationHook?.event, input);
|
|
|
|
|
await runEventHookSafely("sessionNotification", hooks.sessionNotification, input);
|
|
|
|
|
await runEventHookSafely("todoContinuationEnforcer", hooks.todoContinuationEnforcer?.handler, input);
|
|
|
|
|
await runEventHookSafely("unstableAgentBabysitter", hooks.unstableAgentBabysitter?.event, input);
|
|
|
|
|
await runEventHookSafely("contextWindowMonitor", hooks.contextWindowMonitor?.event, input);
|
|
|
|
|
await runEventHookSafely("preemptiveCompaction", hooks.preemptiveCompaction?.event, input);
|
|
|
|
|
await runEventHookSafely("directoryAgentsInjector", hooks.directoryAgentsInjector?.event, input);
|
|
|
|
|
await runEventHookSafely("directoryReadmeInjector", hooks.directoryReadmeInjector?.event, input);
|
|
|
|
|
await runEventHookSafely("rulesInjector", hooks.rulesInjector?.event, input);
|
|
|
|
|
await runEventHookSafely("thinkMode", hooks.thinkMode?.event, input);
|
|
|
|
|
await runEventHookSafely(
|
|
|
|
|
"anthropicContextWindowLimitRecovery",
|
|
|
|
|
hooks.anthropicContextWindowLimitRecovery?.event,
|
|
|
|
|
input,
|
|
|
|
|
);
|
|
|
|
|
await runEventHookSafely("runtimeFallback", hooks.runtimeFallback?.event, input);
|
|
|
|
|
await runEventHookSafely("agentUsageReminder", hooks.agentUsageReminder?.event, input);
|
|
|
|
|
await runEventHookSafely("categorySkillReminder", hooks.categorySkillReminder?.event, input);
|
|
|
|
|
await runEventHookSafely("interactiveBashSession", hooks.interactiveBashSession?.event, input as EventInput);
|
|
|
|
|
await runEventHookSafely("ralphLoop", hooks.ralphLoop?.event, input);
|
|
|
|
|
await runEventHookSafely("stopContinuationGuard", hooks.stopContinuationGuard?.event, input);
|
|
|
|
|
await runEventHookSafely("compactionContextInjector", hooks.compactionContextInjector?.event, input);
|
|
|
|
|
await runEventHookSafely("compactionTodoPreserver", hooks.compactionTodoPreserver?.event, input);
|
|
|
|
|
await runEventHookSafely("writeExistingFileGuard", hooks.writeExistingFileGuard?.event, input);
|
|
|
|
|
await runEventHookSafely("atlasHook", hooks.atlasHook?.handler, input);
|
|
|
|
|
await runEventHookSafely("autoSlashCommand", hooks.autoSlashCommand?.event, input);
|
2026-02-21 15:42:47 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const recentSyntheticIdles = new Map<string, number>();
|
|
|
|
|
const recentRealIdles = new Map<string, number>();
|
2026-04-28 10:47:36 +09:00
|
|
|
const recentAnyIdles = new Map<string, number>();
|
2026-02-21 15:42:47 -07:00
|
|
|
const DEDUP_WINDOW_MS = 500;
|
2026-04-28 10:47:36 +09:00
|
|
|
const teamModeConfig = pluginConfig.team_mode?.enabled ? pluginConfig.team_mode : undefined;
|
|
|
|
|
const teamLeadOrphanHandler = teamModeConfig
|
|
|
|
|
? createTeamLeadOrphanHandler(teamModeConfig, managers.tmuxSessionManager, managers.backgroundManager)
|
|
|
|
|
: undefined;
|
|
|
|
|
const teamMemberErrorHandler = teamModeConfig
|
|
|
|
|
? createTeamMemberErrorHandler(teamModeConfig)
|
|
|
|
|
: undefined;
|
|
|
|
|
const teamMemberStatusHandler = teamModeConfig
|
|
|
|
|
? createTeamMemberStatusHandler(teamModeConfig)
|
|
|
|
|
: undefined;
|
|
|
|
|
const teamIdleWakeHint = teamModeConfig && pluginContext.client.session?.promptAsync
|
|
|
|
|
? createTeamIdleWakeHint({
|
|
|
|
|
directory: pluginContext.directory,
|
|
|
|
|
client: {
|
|
|
|
|
session: {
|
|
|
|
|
promptAsync: pluginContext.client.session.promptAsync,
|
2026-05-15 11:29:55 +09:00
|
|
|
status: pluginContext.client.session.status,
|
2026-04-28 10:47:36 +09:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}, teamModeConfig)
|
|
|
|
|
: undefined;
|
2026-04-04 18:48:03 +09:00
|
|
|
const TMUX_ACTIVITY_EVENT_TYPES = new Set([
|
|
|
|
|
"message.updated",
|
|
|
|
|
"message.part.updated",
|
|
|
|
|
"message.part.delta",
|
|
|
|
|
"message.part.removed",
|
|
|
|
|
"message.removed",
|
|
|
|
|
]);
|
2026-02-10 11:16:44 +09:00
|
|
|
|
2026-02-19 04:41:00 +02:00
|
|
|
const shouldAutoRetrySession = (sessionID: string): boolean => {
|
2026-02-21 15:42:47 -07:00
|
|
|
if (syncSubagentSessions.has(sessionID)) return true;
|
|
|
|
|
const mainSessionID = getMainSessionID();
|
|
|
|
|
if (mainSessionID) return sessionID === mainSessionID;
|
2026-02-19 04:41:00 +02:00
|
|
|
// Headless runs (or resumed sessions) may not emit session.created, so mainSessionID can be unset.
|
|
|
|
|
// In that case, treat any non-subagent session as the "main" interactive session.
|
2026-02-21 15:42:47 -07:00
|
|
|
return !subagentSessions.has(sessionID);
|
|
|
|
|
};
|
2026-02-19 04:41:00 +02:00
|
|
|
|
2026-04-28 10:47:36 +09:00
|
|
|
const shouldDispatchIdleEvent = (sessionID: string, now: number): boolean => {
|
|
|
|
|
const lastDispatchedAt = recentAnyIdles.get(sessionID);
|
|
|
|
|
if (lastDispatchedAt !== undefined && now - lastDispatchedAt < DEDUP_WINDOW_MS) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
recentAnyIdles.set(sessionID, now);
|
|
|
|
|
return true;
|
|
|
|
|
};
|
|
|
|
|
|
2026-05-15 11:45:21 +09:00
|
|
|
const getFallbackContinuationKeys = (fallbackContext?: FallbackContinuationContext): FallbackContinuationDedupeKeys => {
|
2026-05-15 10:44:00 +09:00
|
|
|
const agentKey = fallbackContext?.agentName
|
|
|
|
|
? getAgentConfigKey(fallbackContext.agentName).trim().toLowerCase()
|
|
|
|
|
: "";
|
2026-05-15 11:06:04 +09:00
|
|
|
const providerID = fallbackContext?.dedupeProviderID?.trim().toLowerCase() ?? "";
|
2026-05-15 10:44:00 +09:00
|
|
|
const modelID = fallbackContext?.modelID?.trim().toLowerCase() ?? "";
|
|
|
|
|
|
|
|
|
|
if (!agentKey || !modelID) {
|
2026-05-15 11:06:04 +09:00
|
|
|
return {};
|
2026-05-15 10:44:00 +09:00
|
|
|
}
|
|
|
|
|
|
2026-05-15 11:06:04 +09:00
|
|
|
return {
|
|
|
|
|
modelKey: `${agentKey}:${modelID}`,
|
|
|
|
|
...(providerID ? { providerModelKey: `${agentKey}:${providerID}:${modelID}` } : {}),
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const getFallbackContinuationDedupeState = (sessionID: string): FallbackContinuationDedupeState => {
|
|
|
|
|
const existingState = lastDispatchedModelFallbackContinuationKeys.get(sessionID);
|
|
|
|
|
if (existingState) {
|
|
|
|
|
return existingState;
|
2026-05-15 10:44:00 +09:00
|
|
|
}
|
2026-05-15 11:06:04 +09:00
|
|
|
|
|
|
|
|
const state = {
|
|
|
|
|
modelKeys: new Set<string>(),
|
|
|
|
|
providerModelKeys: new Set<string>(),
|
|
|
|
|
providerlessModelKeys: new Set<string>(),
|
|
|
|
|
};
|
|
|
|
|
lastDispatchedModelFallbackContinuationKeys.set(sessionID, state);
|
|
|
|
|
return state;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const wasFallbackContinuationAlreadyDispatched = (
|
|
|
|
|
state: FallbackContinuationDedupeState | undefined,
|
|
|
|
|
keys: FallbackContinuationDedupeKeys,
|
|
|
|
|
): boolean => {
|
|
|
|
|
if (!state || !keys.modelKey) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!keys.providerModelKey) {
|
|
|
|
|
return state.modelKeys.has(keys.modelKey);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return state.providerModelKeys.has(keys.providerModelKey) || state.providerlessModelKeys.has(keys.modelKey);
|
2026-05-15 10:44:00 +09:00
|
|
|
};
|
|
|
|
|
|
2026-05-15 11:45:21 +09:00
|
|
|
const shouldSkipFallbackContinuation = (
|
2026-04-28 10:47:36 +09:00
|
|
|
sessionID: string,
|
|
|
|
|
source: string,
|
2026-05-15 11:45:21 +09:00
|
|
|
fallbackContext?: FallbackContinuationContext,
|
|
|
|
|
): boolean => {
|
2026-05-15 10:44:00 +09:00
|
|
|
const fallbackKeys = getFallbackContinuationKeys(fallbackContext);
|
2026-05-15 10:07:35 +09:00
|
|
|
|
|
|
|
|
if (modelFallbackContinuationsInFlight.has(sessionID)) {
|
|
|
|
|
log("[event] model-fallback continuation skipped because one is already in flight", { sessionID, source });
|
2026-05-15 11:45:21 +09:00
|
|
|
return true;
|
2026-05-15 10:07:35 +09:00
|
|
|
}
|
2026-03-04 18:35:09 +01:00
|
|
|
|
2026-05-15 10:44:00 +09:00
|
|
|
const lastDispatchedKeys = lastDispatchedModelFallbackContinuationKeys.get(sessionID);
|
2026-05-15 11:06:04 +09:00
|
|
|
if (wasFallbackContinuationAlreadyDispatched(lastDispatchedKeys, fallbackKeys)) {
|
2026-05-15 10:07:35 +09:00
|
|
|
log("[event] model-fallback continuation skipped because matching fallback was already dispatched", {
|
|
|
|
|
sessionID,
|
|
|
|
|
source,
|
2026-03-04 18:35:09 +01:00
|
|
|
});
|
2026-05-15 11:45:21 +09:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const autoContinueAfterFallback = async (
|
|
|
|
|
sessionID: string,
|
|
|
|
|
source: string,
|
|
|
|
|
fallbackContext?: FallbackContinuationContext,
|
|
|
|
|
): Promise<void> => {
|
|
|
|
|
const fallbackKeys = getFallbackContinuationKeys(fallbackContext);
|
|
|
|
|
|
|
|
|
|
if (shouldSkipFallbackContinuation(sessionID, source, fallbackContext)) {
|
2026-03-04 18:35:09 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-15 10:07:35 +09:00
|
|
|
modelFallbackContinuationsInFlight.add(sessionID);
|
|
|
|
|
let dispatched = false;
|
|
|
|
|
try {
|
|
|
|
|
await pluginContext.client.session.abort({ path: { id: sessionID } }).catch((error) => {
|
|
|
|
|
log("[event] model-fallback abort failed", { sessionID, source, error });
|
|
|
|
|
});
|
2026-05-15 13:19:10 +09:00
|
|
|
releasePromptAsyncReservation(sessionID, `model-fallback-abort:${source}`);
|
2026-05-15 10:07:35 +09:00
|
|
|
|
|
|
|
|
const launchAgent = fallbackContext?.agentName
|
|
|
|
|
? resolveRegisteredAgentName(fallbackContext.agentName)
|
|
|
|
|
: undefined;
|
|
|
|
|
const launchModel = fallbackContext?.providerID && fallbackContext?.modelID
|
|
|
|
|
? { providerID: fallbackContext.providerID, modelID: fallbackContext.modelID }
|
|
|
|
|
: undefined;
|
|
|
|
|
|
|
|
|
|
const agentConfigKey = fallbackContext?.agentName
|
|
|
|
|
? getAgentConfigKey(fallbackContext.agentName)
|
|
|
|
|
: undefined;
|
|
|
|
|
const agentSettings = agentConfigKey
|
|
|
|
|
? pluginConfig.agents?.[agentConfigKey as keyof NonNullable<typeof pluginConfig.agents>]
|
|
|
|
|
: undefined;
|
|
|
|
|
const launchVariant = (agentSettings as { variant?: string } | undefined)?.variant;
|
|
|
|
|
|
|
|
|
|
const promptBody = {
|
|
|
|
|
path: { id: sessionID },
|
|
|
|
|
body: {
|
|
|
|
|
...(launchAgent ? { agent: launchAgent } : {}),
|
|
|
|
|
...(launchModel ? { model: launchModel } : {}),
|
|
|
|
|
...(launchVariant ? { variant: launchVariant } : {}),
|
|
|
|
|
parts: [createInternalAgentContinuationTextPart("continue")],
|
|
|
|
|
},
|
|
|
|
|
query: { directory: pluginContext.directory },
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (typeof pluginContext.client.session.promptAsync === "function") {
|
2026-05-15 11:29:55 +09:00
|
|
|
const promptResult = await promptAsyncAfterSessionIdle({
|
|
|
|
|
client: pluginContext.client,
|
|
|
|
|
sessionID,
|
|
|
|
|
source: `model-fallback:${source}`,
|
|
|
|
|
input: promptBody,
|
|
|
|
|
});
|
|
|
|
|
if (promptResult.status === "dispatched") {
|
2026-05-15 10:07:35 +09:00
|
|
|
dispatched = true;
|
2026-05-15 11:29:55 +09:00
|
|
|
} else if (promptResult.status === "failed") {
|
|
|
|
|
const error = promptResult.error;
|
2026-05-15 10:07:35 +09:00
|
|
|
log("[event] model-fallback promptAsync failed", { sessionID, source, error });
|
2026-05-15 11:29:55 +09:00
|
|
|
} else {
|
|
|
|
|
log("[event] model-fallback promptAsync skipped by gate", { sessionID, source, status: promptResult.status });
|
|
|
|
|
}
|
2026-05-15 10:07:35 +09:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-15 11:50:02 +09:00
|
|
|
const promptResult = await promptAfterSessionIdle({
|
|
|
|
|
client: pluginContext.client,
|
|
|
|
|
sessionID,
|
|
|
|
|
source: `model-fallback:${source}:sync`,
|
|
|
|
|
input: promptBody,
|
2026-05-15 10:07:35 +09:00
|
|
|
});
|
2026-05-15 11:50:02 +09:00
|
|
|
if (promptResult.status === "dispatched") {
|
|
|
|
|
dispatched = true;
|
|
|
|
|
} else if (promptResult.status === "failed") {
|
|
|
|
|
log("[event] model-fallback prompt failed", { sessionID, source, error: promptResult.error });
|
|
|
|
|
} else {
|
|
|
|
|
log("[event] model-fallback prompt skipped by gate", { sessionID, source, status: promptResult.status });
|
|
|
|
|
}
|
2026-05-15 10:07:35 +09:00
|
|
|
} finally {
|
2026-05-15 11:06:04 +09:00
|
|
|
if (dispatched && fallbackKeys.modelKey) {
|
|
|
|
|
const dispatchedKeys = getFallbackContinuationDedupeState(sessionID);
|
|
|
|
|
dispatchedKeys.modelKeys.add(fallbackKeys.modelKey);
|
|
|
|
|
if (fallbackKeys.providerModelKey) {
|
|
|
|
|
dispatchedKeys.providerModelKeys.add(fallbackKeys.providerModelKey);
|
|
|
|
|
} else {
|
|
|
|
|
dispatchedKeys.providerlessModelKeys.add(fallbackKeys.modelKey);
|
2026-05-15 10:44:00 +09:00
|
|
|
}
|
2026-05-15 10:07:35 +09:00
|
|
|
}
|
|
|
|
|
modelFallbackContinuationsInFlight.delete(sessionID);
|
|
|
|
|
}
|
2026-03-04 18:35:09 +01:00
|
|
|
};
|
|
|
|
|
|
2026-02-10 11:16:44 +09:00
|
|
|
return async (input): Promise<void> => {
|
2026-02-10 14:08:02 +09:00
|
|
|
pruneRecentSyntheticIdles({
|
|
|
|
|
recentSyntheticIdles,
|
2026-02-10 19:09:22 +09:00
|
|
|
recentRealIdles,
|
2026-04-28 10:47:36 +09:00
|
|
|
recentAnyIdles,
|
2026-02-10 14:08:02 +09:00
|
|
|
now: Date.now(),
|
|
|
|
|
dedupWindowMs: DEDUP_WINDOW_MS,
|
2026-02-21 15:42:47 -07:00
|
|
|
});
|
2026-02-10 14:08:02 +09:00
|
|
|
|
2026-02-10 11:16:44 +09:00
|
|
|
if (input.event.type === "session.idle") {
|
2026-04-28 10:47:36 +09:00
|
|
|
const sessionID = getEventSessionID(input);
|
2026-02-10 11:16:44 +09:00
|
|
|
if (sessionID) {
|
2026-04-28 10:47:36 +09:00
|
|
|
const now = Date.now();
|
2026-02-21 15:42:47 -07:00
|
|
|
const emittedAt = recentSyntheticIdles.get(sessionID);
|
2026-04-28 10:47:36 +09:00
|
|
|
if (emittedAt !== undefined && now - emittedAt < DEDUP_WINDOW_MS) {
|
2026-02-21 15:42:47 -07:00
|
|
|
recentSyntheticIdles.delete(sessionID);
|
2026-05-10 14:54:01 +09:00
|
|
|
// Let real idle events through even when a synthetic idle fired moments earlier.
|
|
|
|
|
// OpenCode diagnostics expect a concrete session.idle event signal.
|
2026-05-11 08:45:34 +09:00
|
|
|
const lastAnyIdleAt = recentAnyIdles.get(sessionID);
|
|
|
|
|
if (lastAnyIdleAt === emittedAt) {
|
|
|
|
|
recentAnyIdles.delete(sessionID);
|
|
|
|
|
}
|
2026-02-10 11:16:44 +09:00
|
|
|
}
|
2026-04-28 10:47:36 +09:00
|
|
|
recentRealIdles.set(sessionID, now);
|
|
|
|
|
if (!shouldDispatchIdleEvent(sessionID, now)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-02-10 11:16:44 +09:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-21 15:42:47 -07:00
|
|
|
await dispatchToHooks(input);
|
2026-02-10 11:16:44 +09:00
|
|
|
|
2026-02-21 15:42:47 -07:00
|
|
|
const syntheticIdle = normalizeSessionStatusToIdle(input);
|
2026-02-10 11:16:44 +09:00
|
|
|
if (syntheticIdle) {
|
2026-02-21 15:42:47 -07:00
|
|
|
const sessionID = (syntheticIdle.event.properties as Record<string, unknown>)?.sessionID as string;
|
2026-04-28 10:47:36 +09:00
|
|
|
const now = Date.now();
|
2026-02-21 15:42:47 -07:00
|
|
|
const emittedAt = recentRealIdles.get(sessionID);
|
2026-04-28 10:47:36 +09:00
|
|
|
if (emittedAt !== undefined && now - emittedAt < DEDUP_WINDOW_MS) {
|
2026-02-21 15:42:47 -07:00
|
|
|
recentRealIdles.delete(sessionID);
|
|
|
|
|
return;
|
2026-02-10 19:09:22 +09:00
|
|
|
}
|
2026-04-28 10:47:36 +09:00
|
|
|
recentSyntheticIdles.set(sessionID, now);
|
|
|
|
|
if (!shouldDispatchIdleEvent(sessionID, now)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-02-21 15:42:47 -07:00
|
|
|
await dispatchToHooks(syntheticIdle as EventInput);
|
2026-04-07 22:49:37 +09:00
|
|
|
if (pluginConfig.openclaw) {
|
|
|
|
|
await dispatchOpenClawEvent({
|
|
|
|
|
config: pluginConfig.openclaw,
|
|
|
|
|
rawEvent: "session.idle",
|
|
|
|
|
context: {
|
|
|
|
|
sessionId: sessionID,
|
|
|
|
|
projectPath: pluginContext.directory,
|
|
|
|
|
tmuxPaneId: managers.tmuxSessionManager.getTrackedPaneId?.(sessionID) ?? process.env.TMUX_PANE,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
2026-02-10 11:16:44 +09:00
|
|
|
}
|
2026-02-08 16:25:25 +09:00
|
|
|
|
2026-02-21 15:42:47 -07:00
|
|
|
const { event } = input;
|
|
|
|
|
const props = event.properties as Record<string, unknown> | undefined;
|
2026-02-08 16:25:25 +09:00
|
|
|
|
2026-04-05 13:27:50 +09:00
|
|
|
if (tmuxIntegrationEnabled && TMUX_ACTIVITY_EVENT_TYPES.has(event.type)) {
|
2026-04-04 18:48:03 +09:00
|
|
|
managers.tmuxSessionManager.onEvent?.(event as { type: string; properties?: Record<string, unknown> });
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-08 16:25:25 +09:00
|
|
|
if (event.type === "session.created") {
|
2026-02-21 15:42:47 -07:00
|
|
|
const sessionInfo = props?.info as { id?: string; title?: string; parentID?: string } | undefined;
|
2026-05-12 11:48:18 +09:00
|
|
|
const sessionID = resolveSessionEventID(props);
|
|
|
|
|
const isSubagentSession = !!sessionInfo?.parentID || !!sessionID && subagentSessions.has(sessionID);
|
2026-02-08 16:25:25 +09:00
|
|
|
|
2026-04-28 10:47:36 +09:00
|
|
|
if (!isSubagentSession) {
|
2026-05-12 11:48:18 +09:00
|
|
|
setMainSession(sessionID);
|
2026-02-08 16:25:25 +09:00
|
|
|
}
|
|
|
|
|
|
2026-02-21 15:42:47 -07:00
|
|
|
firstMessageVariantGate.markSessionCreated(sessionInfo);
|
2026-02-08 16:25:25 +09:00
|
|
|
|
2026-04-28 10:47:36 +09:00
|
|
|
// Subagent sessions are registered by the specialized background/delegate callbacks.
|
|
|
|
|
if (tmuxIntegrationEnabled && !isSubagentSession) {
|
2026-04-05 13:27:50 +09:00
|
|
|
await managers.tmuxSessionManager.onSessionCreated(
|
|
|
|
|
event as {
|
|
|
|
|
type: string;
|
|
|
|
|
properties?: {
|
|
|
|
|
info?: { id?: string; parentID?: string; title?: string };
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
}
|
2026-04-07 22:49:37 +09:00
|
|
|
|
2026-04-10 18:47:18 +09:00
|
|
|
// Skip subagent sessions — they are dispatched by specialized callbacks
|
|
|
|
|
// in create-managers.ts (async) and tool-registry.ts (sync)
|
2026-05-12 11:48:18 +09:00
|
|
|
if (pluginConfig.openclaw && sessionID && !isSubagentSession) {
|
2026-04-07 22:49:37 +09:00
|
|
|
await dispatchOpenClawEvent({
|
|
|
|
|
config: pluginConfig.openclaw,
|
|
|
|
|
rawEvent: event.type,
|
|
|
|
|
context: {
|
2026-05-12 11:48:18 +09:00
|
|
|
sessionId: sessionID,
|
2026-04-07 22:49:37 +09:00
|
|
|
projectPath: pluginContext.directory,
|
2026-05-12 11:48:18 +09:00
|
|
|
tmuxPaneId: managers.tmuxSessionManager.getTrackedPaneId?.(sessionID) ?? process.env.TMUX_PANE,
|
2026-04-07 22:49:37 +09:00
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
2026-02-08 16:25:25 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (event.type === "session.deleted") {
|
2026-05-12 11:48:18 +09:00
|
|
|
const sessionID = resolveSessionEventID(props);
|
|
|
|
|
if (sessionID === getMainSessionID()) {
|
2026-02-21 15:42:47 -07:00
|
|
|
setMainSession(undefined);
|
2026-02-08 16:25:25 +09:00
|
|
|
}
|
|
|
|
|
|
2026-05-12 11:48:18 +09:00
|
|
|
if (sessionID) {
|
|
|
|
|
const wasSyncSubagentSession = syncSubagentSessions.has(sessionID);
|
|
|
|
|
clearSessionAgent(sessionID);
|
|
|
|
|
lastHandledModelErrorMessageID.delete(sessionID);
|
|
|
|
|
lastHandledRetryStatusKey.delete(sessionID);
|
|
|
|
|
lastKnownModelBySession.delete(sessionID);
|
2026-05-15 10:07:35 +09:00
|
|
|
modelFallbackContinuationsInFlight.delete(sessionID);
|
2026-05-15 10:44:00 +09:00
|
|
|
lastDispatchedModelFallbackContinuationKeys.delete(sessionID);
|
2026-04-18 02:35:46 +09:00
|
|
|
if (modelFallback) {
|
2026-05-12 11:48:18 +09:00
|
|
|
clearPendingModelFallback(modelFallback, sessionID);
|
|
|
|
|
clearSessionFallbackChain(modelFallback, sessionID);
|
2026-04-18 02:35:46 +09:00
|
|
|
}
|
2026-05-12 11:48:18 +09:00
|
|
|
resetMessageCursor(sessionID);
|
|
|
|
|
clearBackgroundOutputConsumptionsForParentSession(sessionID);
|
|
|
|
|
clearBackgroundOutputConsumptionsForTaskSession(sessionID);
|
|
|
|
|
firstMessageVariantGate.clear(sessionID);
|
|
|
|
|
clearSessionModel(sessionID);
|
|
|
|
|
clearSessionPromptParams(sessionID);
|
|
|
|
|
syncSubagentSessions.delete(sessionID);
|
2026-04-07 22:49:37 +09:00
|
|
|
if (pluginConfig.openclaw) {
|
|
|
|
|
await dispatchOpenClawEvent({
|
|
|
|
|
config: pluginConfig.openclaw,
|
|
|
|
|
rawEvent: event.type,
|
|
|
|
|
context: {
|
2026-05-12 11:48:18 +09:00
|
|
|
sessionId: sessionID,
|
2026-04-07 22:49:37 +09:00
|
|
|
projectPath: pluginContext.directory,
|
2026-05-12 11:48:18 +09:00
|
|
|
tmuxPaneId: managers.tmuxSessionManager.getTrackedPaneId?.(sessionID) ?? process.env.TMUX_PANE,
|
2026-04-07 22:49:37 +09:00
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
2026-03-13 10:56:44 +09:00
|
|
|
if (wasSyncSubagentSession) {
|
2026-05-12 11:48:18 +09:00
|
|
|
subagentSessions.delete(sessionID);
|
2026-03-13 10:56:44 +09:00
|
|
|
}
|
2026-05-12 11:48:18 +09:00
|
|
|
deleteSessionTools(sessionID);
|
|
|
|
|
await managers.skillMcpManager.disconnectSession(sessionID);
|
2026-02-21 15:42:47 -07:00
|
|
|
await lspManager.cleanupTempDirectoryClients();
|
2026-04-05 13:27:50 +09:00
|
|
|
if (tmuxIntegrationEnabled) {
|
|
|
|
|
await managers.tmuxSessionManager.onSessionDeleted({
|
2026-05-12 11:48:18 +09:00
|
|
|
sessionID,
|
2026-04-05 13:27:50 +09:00
|
|
|
});
|
|
|
|
|
}
|
2026-02-08 16:25:25 +09:00
|
|
|
}
|
2026-04-28 10:47:36 +09:00
|
|
|
|
|
|
|
|
await runEventHookSafely("teamLeadOrphanHandler", teamLeadOrphanHandler, input);
|
|
|
|
|
await runEventHookSafely("teamMemberStatusHandler", teamMemberStatusHandler, input);
|
2026-02-08 16:25:25 +09:00
|
|
|
}
|
|
|
|
|
|
2026-03-29 04:53:36 +09:00
|
|
|
if (event.type === "message.removed") {
|
|
|
|
|
const messageID = props?.messageID as string | undefined;
|
2026-05-12 11:48:18 +09:00
|
|
|
const sessionID = resolveMessageEventSessionID(props);
|
2026-03-29 04:53:36 +09:00
|
|
|
restoreBackgroundOutputConsumption(sessionID, messageID);
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-07 22:49:37 +09:00
|
|
|
if (event.type === "session.idle" && pluginConfig.openclaw) {
|
2026-05-12 11:48:18 +09:00
|
|
|
const sessionID = resolveSessionEventID(props);
|
2026-04-07 22:49:37 +09:00
|
|
|
if (sessionID) {
|
|
|
|
|
await dispatchOpenClawEvent({
|
|
|
|
|
config: pluginConfig.openclaw,
|
|
|
|
|
rawEvent: event.type,
|
|
|
|
|
context: {
|
|
|
|
|
sessionId: sessionID,
|
|
|
|
|
projectPath: pluginContext.directory,
|
|
|
|
|
tmuxPaneId: managers.tmuxSessionManager.getTrackedPaneId?.(sessionID) ?? process.env.TMUX_PANE,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-28 10:47:36 +09:00
|
|
|
if (event.type === "session.idle") {
|
|
|
|
|
managers.tmuxSessionManager?.onEvent?.(event);
|
|
|
|
|
await runEventHookSafely("teamIdleWakeHint", teamIdleWakeHint, input);
|
|
|
|
|
await runEventHookSafely("teamMemberStatusHandler", teamMemberStatusHandler, input);
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-08 16:25:25 +09:00
|
|
|
if (event.type === "message.updated") {
|
2026-02-21 15:42:47 -07:00
|
|
|
const info = props?.info as Record<string, unknown> | undefined;
|
2026-05-12 11:48:18 +09:00
|
|
|
const sessionID = resolveMessageEventSessionID(props);
|
2026-02-21 15:42:47 -07:00
|
|
|
const agent = info?.agent as string | undefined;
|
|
|
|
|
const role = info?.role as string | undefined;
|
2026-04-28 17:59:25 +09:00
|
|
|
if (sessionID && info?.finish === true) {
|
|
|
|
|
invalidateContextWindowUsageCache(pluginContext as PluginInput, sessionID);
|
|
|
|
|
}
|
2026-02-19 04:41:00 +02:00
|
|
|
if (sessionID && role === "user") {
|
2026-03-11 21:57:06 +09:00
|
|
|
const isCompactionMessage = agent ? isCompactionAgent(agent) : false;
|
|
|
|
|
if (agent && !isCompactionMessage) {
|
2026-02-21 15:42:47 -07:00
|
|
|
updateSessionAgent(sessionID, agent);
|
2026-02-19 04:41:00 +02:00
|
|
|
}
|
2026-02-21 15:42:47 -07:00
|
|
|
const providerID = info?.providerID as string | undefined;
|
|
|
|
|
const modelID = info?.modelID as string | undefined;
|
2026-03-11 21:57:06 +09:00
|
|
|
if (providerID && modelID && !isCompactionMessage) {
|
2026-02-21 15:42:47 -07:00
|
|
|
lastKnownModelBySession.set(sessionID, { providerID, modelID });
|
|
|
|
|
setSessionModel(sessionID, { providerID, modelID });
|
2026-02-19 04:41:00 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Model fallback: in practice, API/model failures often surface as assistant message errors.
|
|
|
|
|
// session.error events are not guaranteed for all providers, so we also observe message.updated.
|
2026-02-22 17:25:04 +09:00
|
|
|
if (sessionID && role === "assistant" && !isRuntimeFallbackEnabled && isModelFallbackEnabled) {
|
2026-02-21 05:59:30 +09:00
|
|
|
try {
|
2026-02-21 15:42:47 -07:00
|
|
|
const assistantMessageID = info?.id as string | undefined;
|
|
|
|
|
const assistantError = info?.error;
|
2026-02-21 05:59:30 +09:00
|
|
|
if (assistantMessageID && assistantError) {
|
2026-02-21 15:42:47 -07:00
|
|
|
const lastHandled = lastHandledModelErrorMessageID.get(sessionID);
|
2026-02-21 05:59:30 +09:00
|
|
|
if (lastHandled === assistantMessageID) {
|
2026-02-21 15:42:47 -07:00
|
|
|
return;
|
2026-02-21 05:59:30 +09:00
|
|
|
}
|
|
|
|
|
|
2026-02-21 15:42:47 -07:00
|
|
|
const errorName = extractErrorName(assistantError);
|
|
|
|
|
const errorMessage = extractErrorMessage(assistantError);
|
|
|
|
|
const errorInfo = { name: errorName, message: errorMessage };
|
2026-02-21 05:59:30 +09:00
|
|
|
|
|
|
|
|
if (shouldRetryError(errorInfo)) {
|
|
|
|
|
// Prefer the agent/model/provider from the assistant message payload.
|
2026-02-21 15:42:47 -07:00
|
|
|
let agentName = agent ?? getSessionAgent(sessionID);
|
2026-02-21 05:59:30 +09:00
|
|
|
if (!agentName && sessionID === getMainSessionID()) {
|
|
|
|
|
if (errorMessage.includes("claude-opus") || errorMessage.includes("opus")) {
|
2026-02-21 15:42:47 -07:00
|
|
|
agentName = "sisyphus";
|
2026-02-21 05:59:30 +09:00
|
|
|
} else if (errorMessage.includes("gpt-5")) {
|
2026-02-21 15:42:47 -07:00
|
|
|
agentName = "hephaestus";
|
2026-02-21 05:59:30 +09:00
|
|
|
} else {
|
2026-02-21 15:42:47 -07:00
|
|
|
agentName = "sisyphus";
|
2026-02-21 05:59:30 +09:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (agentName) {
|
2026-05-15 11:06:04 +09:00
|
|
|
const providerHint = info?.providerID as string | undefined;
|
|
|
|
|
const currentProvider = resolveFallbackProviderID(sessionID, providerHint);
|
2026-04-17 14:51:52 +09:00
|
|
|
const rawModel = (info?.modelID as string | undefined) ?? "claude-opus-4-7";
|
2026-02-21 15:42:47 -07:00
|
|
|
const currentModel = normalizeFallbackModelID(rawModel);
|
2026-05-15 11:45:21 +09:00
|
|
|
const fallbackContext = {
|
|
|
|
|
agentName,
|
|
|
|
|
providerID: currentProvider,
|
|
|
|
|
dedupeProviderID: providerHint,
|
|
|
|
|
modelID: currentModel,
|
|
|
|
|
};
|
|
|
|
|
const shouldAutoContinue = shouldAutoRetrySession(sessionID) &&
|
|
|
|
|
!hooks.stopContinuationGuard?.isStopped(sessionID);
|
2026-02-21 05:59:30 +09:00
|
|
|
|
2026-05-15 11:45:21 +09:00
|
|
|
if (!shouldAutoContinue || !shouldSkipFallbackContinuation(sessionID, "message.updated", fallbackContext)) {
|
|
|
|
|
applyUserConfiguredFallbackChain(modelFallback, sessionID, agentName, currentProvider, args.pluginConfig);
|
|
|
|
|
|
|
|
|
|
const setFallback = modelFallback
|
|
|
|
|
? setPendingModelFallback(modelFallback, sessionID, agentName, currentProvider, currentModel)
|
|
|
|
|
: false;
|
2026-02-21 05:59:30 +09:00
|
|
|
|
2026-05-15 11:45:21 +09:00
|
|
|
if (setFallback && shouldAutoContinue) {
|
|
|
|
|
lastHandledModelErrorMessageID.set(sessionID, assistantMessageID);
|
|
|
|
|
await autoContinueAfterFallback(sessionID, "message.updated", fallbackContext);
|
|
|
|
|
}
|
2026-02-21 05:59:30 +09:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-02-19 04:41:00 +02:00
|
|
|
}
|
2026-02-21 05:59:30 +09:00
|
|
|
} catch (err) {
|
2026-02-21 15:42:47 -07:00
|
|
|
log("[event] model-fallback error in message.updated:", { sessionID, error: err });
|
2026-02-21 05:59:30 +09:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (event.type === "session.status") {
|
2026-05-12 11:48:18 +09:00
|
|
|
const sessionID = resolveSessionEventID(props);
|
2026-02-21 15:42:47 -07:00
|
|
|
const status = props?.status as { type?: string; attempt?: number; message?: string; next?: number } | undefined;
|
2026-02-19 04:41:00 +02:00
|
|
|
|
2026-03-17 15:17:34 +09:00
|
|
|
// Retry dedupe lifecycle: set key when a retry status is handled, clear it after recovery
|
|
|
|
|
// (non-retry idle) so future failures with the same key can trigger fallback again.
|
|
|
|
|
if (sessionID && status?.type === "idle") {
|
|
|
|
|
lastHandledRetryStatusKey.delete(sessionID);
|
2026-05-15 10:44:00 +09:00
|
|
|
lastDispatchedModelFallbackContinuationKeys.delete(sessionID);
|
2026-03-17 15:17:34 +09:00
|
|
|
}
|
|
|
|
|
|
2026-03-04 18:35:09 +01:00
|
|
|
if (sessionID && status?.type === "retry" && isModelFallbackEnabled && !isRuntimeFallbackEnabled) {
|
2026-02-21 05:59:30 +09:00
|
|
|
try {
|
2026-02-21 15:42:47 -07:00
|
|
|
const retryMessage = typeof status.message === "string" ? status.message : "";
|
2026-03-04 18:35:09 +01:00
|
|
|
const parsedForKey = extractProviderModelFromErrorMessage(retryMessage);
|
|
|
|
|
const retryAttempt = extractRetryAttempt(status.attempt, retryMessage);
|
|
|
|
|
// Deduplicate countdown updates for the same retry attempt/model.
|
|
|
|
|
// Messages like "retrying in 7m 56s" change every second but should only trigger once.
|
|
|
|
|
const retryKey = `${retryAttempt}:${parsedForKey.providerID ?? ""}/${parsedForKey.modelID ?? ""}:${normalizeRetryStatusMessage(retryMessage)}`;
|
2026-02-21 05:59:30 +09:00
|
|
|
if (lastHandledRetryStatusKey.get(sessionID) === retryKey) {
|
2026-02-21 15:42:47 -07:00
|
|
|
return;
|
2026-02-21 05:59:30 +09:00
|
|
|
}
|
2026-02-21 15:42:47 -07:00
|
|
|
lastHandledRetryStatusKey.set(sessionID, retryKey);
|
2026-02-19 04:41:00 +02:00
|
|
|
|
2026-02-21 15:42:47 -07:00
|
|
|
const errorInfo = { name: undefined as string | undefined, message: retryMessage };
|
2026-02-19 04:41:00 +02:00
|
|
|
if (shouldRetryError(errorInfo)) {
|
2026-02-21 15:42:47 -07:00
|
|
|
let agentName = getSessionAgent(sessionID);
|
2026-02-19 04:41:00 +02:00
|
|
|
if (!agentName && sessionID === getMainSessionID()) {
|
2026-02-21 05:59:30 +09:00
|
|
|
if (retryMessage.includes("claude-opus") || retryMessage.includes("opus")) {
|
2026-02-21 15:42:47 -07:00
|
|
|
agentName = "sisyphus";
|
2026-02-21 05:59:30 +09:00
|
|
|
} else if (retryMessage.includes("gpt-5")) {
|
2026-02-21 15:42:47 -07:00
|
|
|
agentName = "hephaestus";
|
2026-02-19 04:41:00 +02:00
|
|
|
} else {
|
2026-02-21 15:42:47 -07:00
|
|
|
agentName = "sisyphus";
|
2026-02-19 04:41:00 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (agentName) {
|
2026-02-21 15:42:47 -07:00
|
|
|
const parsed = extractProviderModelFromErrorMessage(retryMessage);
|
|
|
|
|
const lastKnown = lastKnownModelBySession.get(sessionID);
|
2026-03-12 01:49:16 +09:00
|
|
|
const currentProvider = resolveFallbackProviderID(sessionID, parsed.providerID);
|
2026-04-17 14:51:52 +09:00
|
|
|
let currentModel = parsed.modelID ?? lastKnown?.modelID ?? "claude-opus-4-7";
|
2026-02-21 15:42:47 -07:00
|
|
|
currentModel = normalizeFallbackModelID(currentModel);
|
2026-05-15 11:45:21 +09:00
|
|
|
const fallbackContext = {
|
|
|
|
|
agentName,
|
|
|
|
|
providerID: currentProvider,
|
|
|
|
|
dedupeProviderID: parsed.providerID,
|
|
|
|
|
modelID: currentModel,
|
|
|
|
|
};
|
|
|
|
|
const shouldAutoContinue = shouldAutoRetrySession(sessionID) &&
|
|
|
|
|
!hooks.stopContinuationGuard?.isStopped(sessionID);
|
2026-02-21 15:42:47 -07:00
|
|
|
|
2026-05-15 11:45:21 +09:00
|
|
|
if (!shouldAutoContinue || !shouldSkipFallbackContinuation(sessionID, "session.status", fallbackContext)) {
|
|
|
|
|
applyUserConfiguredFallbackChain(modelFallback, sessionID, agentName, currentProvider, args.pluginConfig);
|
2026-02-21 15:42:47 -07:00
|
|
|
|
2026-05-15 11:45:21 +09:00
|
|
|
const setFallback = modelFallback
|
|
|
|
|
? setPendingModelFallback(modelFallback, sessionID, agentName, currentProvider, currentModel)
|
|
|
|
|
: false;
|
|
|
|
|
|
|
|
|
|
if (setFallback && shouldAutoContinue) {
|
|
|
|
|
await autoContinueAfterFallback(sessionID, "session.status", fallbackContext);
|
|
|
|
|
}
|
2026-02-19 04:41:00 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-02-21 05:59:30 +09:00
|
|
|
} catch (err) {
|
2026-02-21 15:42:47 -07:00
|
|
|
log("[event] model-fallback error in session.status:", { sessionID, error: err });
|
2026-02-19 04:41:00 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-21 05:59:30 +09:00
|
|
|
if (event.type === "session.error") {
|
|
|
|
|
try {
|
2026-05-12 11:48:18 +09:00
|
|
|
const sessionID = resolveSessionEventID(props);
|
2026-02-21 15:42:47 -07:00
|
|
|
const error = props?.error;
|
2026-02-21 05:59:30 +09:00
|
|
|
|
2026-02-21 15:42:47 -07:00
|
|
|
const errorName = extractErrorName(error);
|
|
|
|
|
const errorMessage = extractErrorMessage(error);
|
|
|
|
|
const errorInfo = { name: errorName, message: errorMessage };
|
2026-02-21 05:59:30 +09:00
|
|
|
|
|
|
|
|
// First, try session recovery for internal errors (thinking blocks, tool results, etc.)
|
|
|
|
|
if (hooks.sessionRecovery?.isRecoverableError(error)) {
|
|
|
|
|
const messageInfo = {
|
|
|
|
|
id: props?.messageID as string | undefined,
|
|
|
|
|
role: "assistant" as const,
|
|
|
|
|
sessionID,
|
|
|
|
|
error,
|
2026-02-21 15:42:47 -07:00
|
|
|
};
|
|
|
|
|
const recovered = await hooks.sessionRecovery.handleSessionRecovery(messageInfo);
|
2026-02-21 05:59:30 +09:00
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
recovered &&
|
|
|
|
|
sessionID &&
|
|
|
|
|
sessionID === getMainSessionID() &&
|
|
|
|
|
!hooks.stopContinuationGuard?.isStopped(sessionID)
|
|
|
|
|
) {
|
2026-03-23 18:12:51 +09:00
|
|
|
// Trigger compaction before sending "continue" to avoid double-sending continuation
|
|
|
|
|
await pluginContext.client.session
|
|
|
|
|
.summarize({
|
|
|
|
|
path: { id: sessionID },
|
|
|
|
|
body: { auto: true },
|
|
|
|
|
query: { directory: pluginContext.directory },
|
|
|
|
|
})
|
|
|
|
|
.catch((err: unknown) => {
|
|
|
|
|
log("[event] compaction before recovery continue failed:", { sessionID, error: err });
|
|
|
|
|
});
|
|
|
|
|
|
2026-05-15 11:50:02 +09:00
|
|
|
const promptResult = await promptAfterSessionIdle({
|
|
|
|
|
client: pluginContext.client,
|
|
|
|
|
sessionID,
|
|
|
|
|
source: "session-recovery:post-compaction-continue",
|
|
|
|
|
input: {
|
2026-02-21 05:59:30 +09:00
|
|
|
path: { id: sessionID },
|
2026-05-13 13:36:25 +09:00
|
|
|
body: { parts: [createInternalAgentContinuationTextPart("continue")] },
|
2026-02-21 16:24:18 +09:00
|
|
|
query: { directory: pluginContext.directory },
|
2026-05-15 11:50:02 +09:00
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
if (promptResult.status === "failed") {
|
|
|
|
|
log("[event] recovery continue prompt failed", { sessionID, error: promptResult.error });
|
|
|
|
|
} else if (promptResult.status !== "dispatched") {
|
|
|
|
|
log("[event] recovery continue prompt skipped by gate", { sessionID, status: promptResult.status });
|
|
|
|
|
}
|
2026-02-21 05:59:30 +09:00
|
|
|
}
|
2026-02-21 15:42:47 -07:00
|
|
|
}
|
2026-02-21 05:59:30 +09:00
|
|
|
// Second, try model fallback for model errors (rate limit, quota, provider issues, etc.)
|
2026-02-22 17:25:04 +09:00
|
|
|
else if (sessionID && shouldRetryError(errorInfo) && !isRuntimeFallbackEnabled && isModelFallbackEnabled) {
|
2026-02-21 15:42:47 -07:00
|
|
|
let agentName = getSessionAgent(sessionID);
|
|
|
|
|
|
2026-02-19 04:41:00 +02:00
|
|
|
if (!agentName && sessionID === getMainSessionID()) {
|
2026-02-21 05:59:30 +09:00
|
|
|
if (errorMessage.includes("claude-opus") || errorMessage.includes("opus")) {
|
2026-02-21 15:42:47 -07:00
|
|
|
agentName = "sisyphus";
|
2026-02-21 05:59:30 +09:00
|
|
|
} else if (errorMessage.includes("gpt-5")) {
|
2026-02-21 15:42:47 -07:00
|
|
|
agentName = "hephaestus";
|
2026-02-19 04:41:00 +02:00
|
|
|
} else {
|
2026-02-21 15:42:47 -07:00
|
|
|
agentName = "sisyphus";
|
2026-02-19 04:41:00 +02:00
|
|
|
}
|
|
|
|
|
}
|
2026-02-21 15:42:47 -07:00
|
|
|
|
2026-02-19 04:41:00 +02:00
|
|
|
if (agentName) {
|
2026-02-21 15:42:47 -07:00
|
|
|
const parsed = extractProviderModelFromErrorMessage(errorMessage);
|
2026-05-15 11:06:04 +09:00
|
|
|
const providerHint = (props?.providerID as string | undefined) || parsed.providerID;
|
|
|
|
|
const currentProvider = resolveFallbackProviderID(sessionID, providerHint);
|
2026-04-17 14:51:52 +09:00
|
|
|
let currentModel = (props?.modelID as string) || parsed.modelID || "claude-opus-4-7";
|
2026-02-21 15:42:47 -07:00
|
|
|
currentModel = normalizeFallbackModelID(currentModel);
|
2026-05-15 11:45:21 +09:00
|
|
|
const fallbackContext = {
|
|
|
|
|
agentName,
|
|
|
|
|
providerID: currentProvider,
|
|
|
|
|
dedupeProviderID: providerHint,
|
|
|
|
|
modelID: currentModel,
|
|
|
|
|
};
|
|
|
|
|
const shouldAutoContinue = shouldAutoRetrySession(sessionID) &&
|
|
|
|
|
!hooks.stopContinuationGuard?.isStopped(sessionID);
|
|
|
|
|
|
|
|
|
|
if (!shouldAutoContinue || !shouldSkipFallbackContinuation(sessionID, "session.error", fallbackContext)) {
|
|
|
|
|
applyUserConfiguredFallbackChain(modelFallback, sessionID, agentName, currentProvider, args.pluginConfig);
|
|
|
|
|
|
|
|
|
|
const setFallback = modelFallback
|
|
|
|
|
? setPendingModelFallback(modelFallback, sessionID, agentName, currentProvider, currentModel)
|
|
|
|
|
: false;
|
|
|
|
|
|
|
|
|
|
if (setFallback && shouldAutoContinue) {
|
|
|
|
|
await autoContinueAfterFallback(sessionID, "session.error", fallbackContext);
|
|
|
|
|
}
|
2026-02-19 04:41:00 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-02-21 05:59:30 +09:00
|
|
|
} catch (err) {
|
2026-05-12 11:48:18 +09:00
|
|
|
const sessionID = resolveSessionEventID(props);
|
2026-02-21 15:42:47 -07:00
|
|
|
log("[event] model-fallback error in session.error:", { sessionID, error: err });
|
2026-02-08 16:25:25 +09:00
|
|
|
}
|
2026-04-28 10:47:36 +09:00
|
|
|
|
|
|
|
|
await runEventHookSafely("teamMemberErrorHandler", teamMemberErrorHandler, input);
|
2026-02-08 16:25:25 +09:00
|
|
|
}
|
2026-02-21 15:42:47 -07:00
|
|
|
};
|
2026-02-08 16:25:25 +09:00
|
|
|
}
|