@@ -2711,7 +2711,7 @@ describe("TelegramPollingSession", () => {
27112711 } ) ;
27122712 } ) ;
27132713
2714- it ( "fails buffered spooled claims instead of requeueing when deferred processing times out" , async ( ) => {
2714+ it ( "requeues buffered spooled claims when deferred processing times out" , async ( ) => {
27152715 await withTempSpool ( async ( tempDir ) => {
27162716 const abort = new AbortController ( ) ;
27172717 const log = vi . fn ( ) ;
@@ -2731,15 +2731,15 @@ describe("TelegramPollingSession", () => {
27312731
27322732 await waitForTelegramTestState ( ( ) => expect ( participants ) . toHaveLength ( 1 ) ) ;
27332733 await waitForTelegramTestState ( async ( ) =>
2734- expect ( await failedUpdateIds ( tempDir ) ) . toEqual ( [ 42 ] ) ,
2734+ expect ( await pendingUpdateIds ( tempDir , "all" ) ) . toEqual ( [ 42 ] ) ,
27352735 ) ;
2736- expect ( await pendingUpdateIds ( tempDir , "all" ) ) . toEqual ( [ ] ) ;
2736+ expect ( await failedUpdateIds ( tempDir ) ) . toEqual ( [ ] ) ;
27372737 expect ( await listTelegramSpooledUpdateClaims ( { spoolDir : tempDir } ) ) . toEqual ( [ ] ) ;
27382738 // Core drain watchdog log (display-id stripped of zero padding).
27392739 expectLogIncludes ( log , "claim→adoption stalled for event" ) ;
27402740 expectLogIncludes ( log , "handler-timeout" ) ;
2741- expectLogExcludes ( log , "spooled update 42 failed; keeping for retry" ) ;
2742- expect ( await failedUpdateReasons ( tempDir ) ) . toEqual ( [ { id : 42 , reason : "handler-timeout" } ] ) ;
2741+ expectLogIncludes ( log , "spooled update 42 failed; keeping for retry" ) ;
2742+ expect ( await failedUpdateReasons ( tempDir ) ) . toEqual ( [ ] ) ;
27432743 abort . abort ( ) ;
27442744 stopWorker ( ) ;
27452745 await runPromise ;
@@ -3512,9 +3512,8 @@ describe("TelegramPollingSession", () => {
35123512 } ) ;
35133513 } ) ;
35143514
3515- it ( "recovers a lone active spooled handler owned by a replaced session (#84158)" , async ( ) => {
3516- // Core drain: a lone hanging claim is dead-lettered by the adoption-stall
3517- // watchdog so a replacement session is not blocked forever on that lane.
3515+ it ( "retries a lone active spooled handler in a replacement session (#84158)" , async ( ) => {
3516+ // Core drain releases a hanging claim so a replacement session retries it.
35183517 vi . useFakeTimers ( { shouldAdvanceTime : true } ) ;
35193518 const firstAbort = new AbortController ( ) ;
35203519 const secondAbort = new AbortController ( ) ;
@@ -3524,7 +3523,9 @@ describe("TelegramPollingSession", () => {
35243523 releaseTurn = resolve ;
35253524 } ) ;
35263525 const handleUpdate = vi . fn ( async ( ) => {
3527- await turnDone ;
3526+ if ( handleUpdate . mock . calls . length === 1 ) {
3527+ await turnDone ;
3528+ }
35283529 } ) ;
35293530 createTelegramBotMock . mockImplementation ( ( ) => makeIsolatedBot ( { handleUpdate } ) ) ;
35303531 await writeSpooledTestUpdates ( tempDir , [ topicUpdate ( 42 , 10 , "lone active topic turn" ) ] ) ;
@@ -3558,10 +3559,10 @@ describe("TelegramPollingSession", () => {
35583559 } ) ;
35593560 const firstRunPromise = firstSession . runUntilAbort ( ) ;
35603561 await waitForTelegramTestState ( ( ) => expect ( handleUpdate ) . toHaveBeenCalledTimes ( 1 ) ) ;
3561- // Watchdog dead-letters the hanging claim before the session is replaced.
3562+ // Watchdog releases the hanging claim before the session is replaced.
35623563 await vi . advanceTimersByTimeAsync ( 1_000 ) ;
35633564 await waitForTelegramTestState ( async ( ) =>
3564- expect ( await failedUpdateIds ( tempDir ) ) . toEqual ( [ 42 ] ) ,
3565+ expect ( await pendingUpdateIds ( tempDir , "all" ) ) . toEqual ( [ 42 ] ) ,
35653566 ) ;
35663567 firstAbort . abort ( ) ;
35673568 await vi . advanceTimersByTimeAsync ( 16_000 ) ;
@@ -3578,10 +3579,12 @@ describe("TelegramPollingSession", () => {
35783579 } ,
35793580 } ) ;
35803581 const secondRunPromise = secondSession . runUntilAbort ( ) ;
3581- await vi . advanceTimersByTimeAsync ( 1_000 ) ;
3582- // Tombstoned/failed claim is not re-dispatched; replacement is unblocked.
3583- expect ( handleUpdate ) . toHaveBeenCalledTimes ( 1 ) ;
3584- expect ( await pendingUpdateIds ( tempDir , "all" ) ) . toEqual ( [ ] ) ;
3582+ await vi . advanceTimersByTimeAsync ( 2_000 ) ;
3583+ await waitForTelegramTestState ( ( ) => expect ( handleUpdate ) . toHaveBeenCalledTimes ( 2 ) ) ;
3584+ await waitForTelegramTestState ( async ( ) =>
3585+ expect ( await pendingUpdateIds ( tempDir , "all" ) ) . toEqual ( [ ] ) ,
3586+ ) ;
3587+ expect ( await failedUpdateIds ( tempDir ) ) . toEqual ( [ ] ) ;
35853588
35863589 secondAbort . abort ( ) ;
35873590 await vi . advanceTimersByTimeAsync ( 20_000 ) ;
@@ -4434,10 +4437,8 @@ describe("TelegramPollingSession", () => {
44344437 }
44354438 } ) ;
44364439
4437- it ( "fails a timed-out spooled handler and drains later same-lane updates without restart" , async ( ) => {
4438- // Core drain: adoption-stall dead-letters 42 and frees the lane for 43 on
4439- // the same bot. Session restart on handler timeout is removed private-drain
4440- // behavior; the user-visible outcome is 42 failed and 43 processed.
4440+ it ( "retries a timed-out spooled handler before later same-lane updates without restart" , async ( ) => {
4441+ // Core drain releases 42 for retry before 43 on the same bot.
44414442 vi . useFakeTimers ( { shouldAdvanceTime : true } ) ;
44424443 const abort = new AbortController ( ) ;
44434444 const tempDir = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , "openclaw-telegram-spool-" ) ) ;
@@ -4451,11 +4452,13 @@ describe("TelegramPollingSession", () => {
44514452 init : vi . fn ( async ( ) => undefined ) ,
44524453 handleUpdate : vi . fn ( async ( update : { update_id ?: number } ) => {
44534454 events . push ( `bot:${ update . update_id } ` ) ;
4454- if ( update . update_id === 42 ) {
4455+ if ( update . update_id === 42 && events . filter ( ( event ) => event === "bot:42" ) . length === 1 ) {
44554456 // Hang until the core watchdog aborts the drain lifecycle.
44564457 await new Promise < void > ( ( ) => { } ) ;
44574458 }
4458- abort . abort ( ) ;
4459+ if ( update . update_id === 43 ) {
4460+ abort . abort ( ) ;
4461+ }
44594462 } ) ,
44604463 stop : vi . fn ( async ( ) => undefined ) ,
44614464 } ;
@@ -4482,18 +4485,16 @@ describe("TelegramPollingSession", () => {
44824485 const runPromise = session . runUntilAbort ( ) ;
44834486 await waitForTelegramTestState ( ( ) => expect ( events ) . toEqual ( [ "bot:42" ] ) ) ;
44844487
4485- await vi . advanceTimersByTimeAsync ( 1_000 ) ;
4486- await waitForTelegramTestState ( async ( ) =>
4487- expect ( await failedUpdateIds ( tempDir ) ) . toEqual ( [ 42 ] ) ,
4488- ) ;
4489- await waitForTelegramTestState ( ( ) => expect ( events ) . toEqual ( [ "bot:42" , "bot:43" ] ) ) ;
4488+ await vi . advanceTimersByTimeAsync ( 2_000 ) ;
4489+ await waitForTelegramTestState ( ( ) => expect ( events ) . toEqual ( [ "bot:42" , "bot:42" , "bot:43" ] ) ) ;
44904490 await vi . advanceTimersByTimeAsync ( 15_000 ) ;
44914491 await runPromise ;
44924492
44934493 // No private-drain session restart for handler timeout.
44944494 expect ( worker . createWorker ) . toHaveBeenCalledTimes ( 1 ) ;
44954495 expect ( createTelegramBotMock ) . toHaveBeenCalledTimes ( 1 ) ;
44964496 expect ( await pendingUpdateIds ( tempDir , "all" ) ) . toEqual ( [ ] ) ;
4497+ expect ( await failedUpdateIds ( tempDir ) ) . toEqual ( [ ] ) ;
44974498 expectLogIncludes ( log , "handler-timeout" ) ;
44984499 } finally {
44994500 abort . abort ( ) ;
0 commit comments