@@ -698,12 +698,46 @@ function alertTraceDelivery(content: string, filename: string, trace: string): A
698698 } ;
699699}
700700
701- export function fatalAlertDelivery ( title : string , trace : string ) : AlertTraceDelivery {
702- return alertTraceDelivery ( `**FATAL: ${ title } **` , "fatal-trace.txt" , trace ) ;
701+ /** Identity lines shown in the short Discord alert body (not only the attachment). */
702+ export type AlertIdentity = {
703+ readonly threadId ?: string ;
704+ readonly channelId ?: string ;
705+ } ;
706+
707+ function alertIdentityLines ( identity ?: AlertIdentity ) : ReadonlyArray < string > {
708+ if ( identity === undefined ) return [ ] ;
709+ const lines : string [ ] = [ ] ;
710+ if ( identity . threadId !== undefined && identity . threadId . trim ( ) !== "" ) {
711+ lines . push ( `thread=\`${ identity . threadId } \`` ) ;
712+ }
713+ if ( identity . channelId !== undefined && identity . channelId . trim ( ) !== "" ) {
714+ lines . push ( `channel=\`${ identity . channelId } \`` ) ;
715+ }
716+ return lines ;
717+ }
718+
719+ export function fatalAlertDelivery (
720+ title : string ,
721+ trace : string ,
722+ identity ?: AlertIdentity ,
723+ ) : AlertTraceDelivery {
724+ return alertTraceDelivery (
725+ [ `**FATAL: ${ title } **` , ...alertIdentityLines ( identity ) ] . join ( "\n" ) ,
726+ "fatal-trace.txt" ,
727+ trace ,
728+ ) ;
703729}
704730
705- export function bridgeAlertDelivery ( title : string , trace : string ) : AlertTraceDelivery {
706- return alertTraceDelivery ( `**BRIDGE: ${ title } **` , "bridge-trace.txt" , trace ) ;
731+ export function bridgeAlertDelivery (
732+ title : string ,
733+ trace : string ,
734+ identity ?: AlertIdentity ,
735+ ) : AlertTraceDelivery {
736+ return alertTraceDelivery (
737+ [ `**BRIDGE: ${ title } **` , ...alertIdentityLines ( identity ) ] . join ( "\n" ) ,
738+ "bridge-trace.txt" ,
739+ trace ,
740+ ) ;
707741}
708742
709743export function sessionErrorAlertDelivery ( threadId : string , trace : string ) : AlertTraceDelivery {
@@ -744,14 +778,19 @@ export function formatAlertCause(cause: unknown, maxLen?: number): string {
744778 * or channel unset. Does not require DiscordREST in the caller — uses the
745779 * watchdog-held poster.
746780 */
747- export const postFatalAlert = ( key : string , title : string , detail : string ) =>
781+ export const postFatalAlert = (
782+ key : string ,
783+ title : string ,
784+ detail : string ,
785+ identity ?: AlertIdentity ,
786+ ) =>
748787 Effect . gen ( function * ( ) {
749788 const p = poster ;
750789 if ( p === null ) {
751- yield * Effect . logError ( `Fatal (no alerts channel): ${ title } ` , { detail } ) ;
790+ yield * Effect . logError ( `Fatal (no alerts channel): ${ title } ` , { detail, ... identity } ) ;
752791 return ;
753792 }
754- const delivery = fatalAlertDelivery ( title , detail ) ;
793+ const delivery = fatalAlertDelivery ( title , detail , identity ) ;
755794 yield * p ( `fatal:${ key } ` , delivery . content , FATAL_COOLDOWN_MS , delivery . files ) ;
756795 } ) ;
757796
@@ -760,14 +799,19 @@ export const postFatalAlert = (key: string, title: string, detail: string) =>
760799 * stream/heartbeat Discord errors, and other bridge soft-failures that leave
761800 * Discord threads desynced while T3 still advances.
762801 */
763- export const postBridgeAlert = ( key : string , title : string , detail : string ) =>
802+ export const postBridgeAlert = (
803+ key : string ,
804+ title : string ,
805+ detail : string ,
806+ identity ?: AlertIdentity ,
807+ ) =>
764808 Effect . gen ( function * ( ) {
765809 const p = poster ;
766810 if ( p === null ) {
767- yield * Effect . logError ( `Bridge alert (no alerts channel): ${ title } ` , { detail } ) ;
811+ yield * Effect . logError ( `Bridge alert (no alerts channel): ${ title } ` , { detail, ... identity } ) ;
768812 return ;
769813 }
770- const delivery = bridgeAlertDelivery ( title , detail ) ;
814+ const delivery = bridgeAlertDelivery ( title , detail , identity ) ;
771815 yield * p ( `bridge:${ key } ` , delivery . content , BRIDGE_ALERT_COOLDOWN_MS , delivery . files ) ;
772816 } ) ;
773817
0 commit comments