@@ -144,8 +144,6 @@ import { recoverFailedThreadDraft } from "./recover-failed-thread-draft";
144144import { editingQueuedMessageIdsAtom } from "./use-thread-outbox" ;
145145import {
146146 completeQueuedMessageDelivery ,
147- logThreadOutboxDeliveryFailure ,
148- logThreadOutboxUploadFailure ,
149147 prepareQueuedMessageAttachments ,
150148 recoverEditedCreationAfterDelivery ,
151149 removeAcknowledgedExistingThreadMessage ,
@@ -428,18 +426,7 @@ describe("thread outbox drain delivery cleanup", () => {
428426 const edited = { ...message , text : "edited while the turn delivered" } ;
429427 await harness . manager . update ( edited ) ;
430428
431- // Losing the cleanup race to an edit is expected; it must not warn.
432- const warn = vi . spyOn ( console , "warn" ) . mockImplementation ( ( ) => { } ) ;
433- let outcome : "edited" | "failed" | "removed" ;
434- let warnCalls : ReadonlyArray < unknown [ ] > ;
435- try {
436- outcome = await completeQueuedMessageDelivery ( message , deliveryRevision ) ;
437- warnCalls = [ ...warn . mock . calls ] ;
438- } finally {
439- warn . mockRestore ( ) ;
440- }
441- expect ( outcome ) . toBe ( "edited" ) ;
442- expect ( warnCalls ) . toEqual ( [ ] ) ;
429+ await expect ( completeQueuedMessageDelivery ( message , deliveryRevision ) ) . resolves . toBe ( "edited" ) ;
443430
444431 expect ( remainingMessages ( ) ) . toEqual ( [ edited ] ) ;
445432 expect ( harness . removePersistedFile ) . not . toHaveBeenCalled ( ) ;
@@ -776,156 +763,3 @@ describe("thread outbox recovery rollback", () => {
776763 expect ( harness . setPendingConnectionError ) . toHaveBeenCalledWith ( "too large" ) ;
777764 } ) ;
778765} ) ;
779-
780- describe ( "thread outbox failure logging" , ( ) => {
781- // Tagged errors match shouldRetryThreadOutboxDelivery's transport tags, so
782- // the assertions cover the real failure classification, not a
783- // predetermined action argument.
784- const transportError = { _tag : "RpcClientError" , reason : { _tag : "SocketClose" } } ;
785- const decodeDefectError = { _tag : "RpcClientError" , reason : { _tag : "RpcClientDefect" } } ;
786- const serverDecidedError = { _tag : "OrchestrationDispatchCommandError" } ;
787-
788- function failureLogging ( input : Parameters < typeof logThreadOutboxDeliveryFailure > [ 0 ] ) : {
789- readonly action : string ;
790- readonly warnCalls : ReadonlyArray < unknown [ ] > ;
791- readonly logCalls : ReadonlyArray < unknown [ ] > ;
792- } {
793- const warn = vi . spyOn ( console , "warn" ) . mockImplementation ( ( ) => { } ) ;
794- const log = vi . spyOn ( console , "log" ) . mockImplementation ( ( ) => { } ) ;
795- try {
796- return {
797- action : logThreadOutboxDeliveryFailure ( input ) ,
798- warnCalls : [ ...warn . mock . calls ] ,
799- logCalls : [ ...log . mock . calls ] ,
800- } ;
801- } finally {
802- warn . mockRestore ( ) ;
803- log . mockRestore ( ) ;
804- }
805- }
806-
807- it ( "keeps offline transport retries silent by default at both stages" , ( ) => {
808- for ( const stage of [ "settings-sync" , "start-turn" ] as const ) {
809- const { action, warnCalls, logCalls } = failureLogging ( {
810- stage,
811- error : transportError ,
812- interrupted : false ,
813- context : { messageId : "m1" } ,
814- } ) ;
815- expect ( action ) . toBe ( "retry" ) ;
816- expect ( warnCalls ) . toEqual ( [ ] ) ;
817- expect ( logCalls ) . toEqual ( [ ] ) ;
818- }
819- } ) ;
820-
821- it ( "surfaces transport retry details when the thread-outbox debug filter is enabled" , ( ) => {
822- vi . stubGlobal ( "__T3_DEBUG__" , [ "thread-outbox" ] ) ;
823- const log = vi . spyOn ( console , "log" ) . mockImplementation ( ( ) => { } ) ;
824- try {
825- logThreadOutboxDeliveryFailure ( {
826- stage : "start-turn" ,
827- error : transportError ,
828- interrupted : false ,
829- context : { messageId : "m1" } ,
830- } ) ;
831- expect ( log ) . toHaveBeenCalledWith (
832- "[t3-thread-outbox] queued message delivery failed" ,
833- expect . objectContaining ( { messageId : "m1" , action : "retry" } ) ,
834- ) ;
835- } finally {
836- log . mockRestore ( ) ;
837- vi . unstubAllGlobals ( ) ;
838- }
839- } ) ;
840-
841- it ( "warns when the server decided the message must be restored" , ( ) => {
842- const { action, warnCalls } = failureLogging ( {
843- stage : "start-turn" ,
844- error : serverDecidedError ,
845- interrupted : false ,
846- context : { messageId : "m2" } ,
847- } ) ;
848- expect ( action ) . toBe ( "restore" ) ;
849- expect ( warnCalls ) . toEqual ( [
850- [
851- "[thread-outbox] queued message delivery failed" ,
852- expect . objectContaining ( { messageId : "m2" , action : "restore" } ) ,
853- ] ,
854- ] ) ;
855- } ) ;
856-
857- it ( "warns on a nontransport settings-sync failure even though it resolves to a retry" , ( ) => {
858- const { action, warnCalls } = failureLogging ( {
859- stage : "settings-sync" ,
860- error : serverDecidedError ,
861- interrupted : false ,
862- context : { messageId : "m3" } ,
863- } ) ;
864- expect ( action ) . toBe ( "retry" ) ;
865- expect ( warnCalls ) . toEqual ( [
866- [
867- "[thread-outbox] queued message delivery failed" ,
868- expect . objectContaining ( { stage : "settings-sync" , action : "retry" } ) ,
869- ] ,
870- ] ) ;
871- } ) ;
872-
873- it ( "warns on an rpc response-decoding defect even though it resolves to a retry" , ( ) => {
874- const { action, warnCalls } = failureLogging ( {
875- stage : "start-turn" ,
876- error : decodeDefectError ,
877- interrupted : false ,
878- context : { messageId : "m4" } ,
879- } ) ;
880- expect ( action ) . toBe ( "retry" ) ;
881- expect ( warnCalls ) . toEqual ( [
882- [
883- "[thread-outbox] queued message delivery failed" ,
884- expect . objectContaining ( { stage : "start-turn" , action : "retry" } ) ,
885- ] ,
886- ] ) ;
887- } ) ;
888-
889- it ( "routes retryable attachment-upload failures to the debug log and warns on the rest" , ( ) => {
890- const message = queuedMessage ( { messageId : "m-upload" , text : "with file" } ) ;
891- const warn = vi . spyOn ( console , "warn" ) . mockImplementation ( ( ) => { } ) ;
892- const log = vi . spyOn ( console , "log" ) . mockImplementation ( ( ) => { } ) ;
893- try {
894- logThreadOutboxUploadFailure ( message , transportError ) ;
895- expect ( warn ) . not . toHaveBeenCalled ( ) ;
896- expect ( log ) . not . toHaveBeenCalled ( ) ;
897-
898- logThreadOutboxUploadFailure ( message , serverDecidedError ) ;
899- expect ( warn ) . toHaveBeenCalledWith ( "[thread-outbox] failed to upload attachments" , {
900- environmentId : message . environmentId ,
901- threadId : message . threadId ,
902- messageId : "m-upload" ,
903- error : serverDecidedError ,
904- } ) ;
905- } finally {
906- warn . mockRestore ( ) ;
907- log . mockRestore ( ) ;
908- }
909- } ) ;
910-
911- it ( "logs retryable attachment-upload failures with message identifiers when the debug filter is enabled" , ( ) => {
912- vi . stubGlobal ( "__T3_DEBUG__" , [ "thread-outbox" ] ) ;
913- const message = queuedMessage ( { messageId : "m-upload" , text : "with file" } ) ;
914- const log = vi . spyOn ( console , "log" ) . mockImplementation ( ( ) => { } ) ;
915- try {
916- logThreadOutboxUploadFailure ( message , transportError ) ;
917- expect ( log ) . toHaveBeenCalledWith (
918- "[t3-thread-outbox] attachment upload failed; retrying" ,
919- expect . objectContaining ( {
920- messageId : "m-upload" ,
921- environmentId : message . environmentId ,
922- threadId : message . threadId ,
923- error : transportError ,
924- } ) ,
925- ) ;
926- } finally {
927- log . mockRestore ( ) ;
928- vi . unstubAllGlobals ( ) ;
929- }
930- } ) ;
931- } ) ;
0 commit comments