fix(channel): Feishu channel gateway wont restart after config (#291)

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: Haze <hazeone@users.noreply.github.com>
This commit is contained in:
Haze
2026-03-04 21:45:44 +08:00
committed by GitHub
Unverified
parent 5ddb7d281d
commit be800f6cfc
5 changed files with 186 additions and 9 deletions

View File

@@ -21,3 +21,36 @@ export function getReconnectSkipReason(context: ReconnectAttemptContext): string
}
return null;
}
export type GatewayLifecycleState = 'stopped' | 'starting' | 'running' | 'error' | 'reconnecting';
export interface RestartDeferralContext {
state: GatewayLifecycleState;
startLock: boolean;
}
/**
* Restart requests should not interrupt an in-flight startup/reconnect flow.
* Doing so can kill a just-spawned process and leave the manager stopped.
*/
export function shouldDeferRestart(context: RestartDeferralContext): boolean {
return context.startLock || context.state === 'starting' || context.state === 'reconnecting';
}
export interface DeferredRestartActionContext extends RestartDeferralContext {
hasPendingRestart: boolean;
shouldReconnect: boolean;
}
export type DeferredRestartAction = 'none' | 'wait' | 'drop' | 'execute';
/**
* Decide what to do with a pending deferred restart once lifecycle changes.
*/
export function getDeferredRestartAction(context: DeferredRestartActionContext): DeferredRestartAction {
if (!context.hasPendingRestart) return 'none';
if (shouldDeferRestart(context)) return 'wait';
if (!context.shouldReconnect) return 'drop';
if (context.state === 'running') return 'drop';
return 'execute';
}