fix(mattermost): harden slash abort/lookup error paths

This commit is contained in:
Echo
2026-02-19 10:45:02 -05:00
parent b6cc649dd1
commit db05211bc5
2 changed files with 13 additions and 3 deletions

View File

@@ -1163,7 +1163,10 @@ export async function monitorMattermostProvider(opts: MonitorMattermostOpts = {}
// Clean up slash commands on shutdown
if (slashEnabled) {
const onAbortCleanup = () => {
const runAbortCleanup = () => {
if (slashShutdownCleanup) {
return;
}
// Snapshot registered commands before deactivating state.
// This listener may run concurrently with startup in a new process, so we keep
// monitor shutdown alive until the remote cleanup completes.
@@ -1179,7 +1182,12 @@ export async function monitorMattermostProvider(opts: MonitorMattermostOpts = {}
runtime.error?.(`mattermost: slash cleanup failed: ${String(err)}`);
});
};
opts.abortSignal?.addEventListener("abort", onAbortCleanup, { once: true });
if (opts.abortSignal?.aborted) {
runAbortCleanup();
} else {
opts.abortSignal?.addEventListener("abort", runAbortCleanup, { once: true });
}
}
await runWithReconnect(connectOnce, {

View File

@@ -132,8 +132,9 @@ async function authorizeSlashInvocation(params: {
channelId: string;
senderId: string;
senderName: string;
log?: (msg: string) => void;
}): Promise<SlashInvocationAuth> {
const { account, cfg, client, commandText, channelId, senderId, senderName } = params;
const { account, cfg, client, commandText, channelId, senderId, senderName, log } = params;
const core = getMattermostRuntime();
// Resolve channel info so we can enforce DM vs group/channel policies.
@@ -443,6 +444,7 @@ export function createSlashCommandHttpHandler(params: SlashHttpHandlerParams) {
channelId,
senderId,
senderName,
log,
});
if (!auth.ok) {