@@ -18,10 +18,7 @@ import type { SessionID } from "./schema"
1818import { SessionRetry } from "./retry"
1919import { SessionStatus } from "./status"
2020import { SessionSummary } from "./summary"
21- import { Provider } from "@/provider/provider"
22- import { ProviderFallback } from "@/provider/fallback"
23- import { ProviderV2 } from "@opencode-ai/core/provider"
24- import { ModelV2 } from "@opencode-ai/core/model"
21+ import type { Provider } from "@/provider/provider"
2522import { Question } from "@/question"
2623import { errorMessage } from "@/util/error"
2724import { isRecord } from "@/util/record"
@@ -97,7 +94,6 @@ const layer = Layer.effect(
9794 const image = yield * Image . Service
9895 const events = yield * EventV2Bridge . Service
9996 const database = yield * Database . Service
100- const provider = yield * Provider . Service
10197
10298 const create = Effect . fn ( "SessionProcessor.create" ) ( function * ( input : Input ) {
10399 // Pre-capture snapshot before the LLM stream starts. The AI SDK
@@ -642,73 +638,6 @@ const layer = Layer.effect(
642638 yield * status . set ( ctx . sessionID , { type : "idle" } )
643639 } )
644640
645- const triedFallbacks = new Set < string > ( )
646-
647- const attemptFallback = Effect . fn ( "SessionProcessor.attemptFallback" ) ( function * ( streamInput : LLM . StreamInput , err : unknown ) {
648- const parsed = parse ( err )
649- if ( ! ProviderFallback . shouldFallback ( parsed ) ) {
650- yield * halt ( err )
651- return
652- }
653- const cfg = yield * config . get ( )
654- const next = ProviderFallback . resolveFallback (
655- { providerID : input . model . providerID , modelID : input . model . id } ,
656- cfg ,
657- triedFallbacks ,
658- )
659- if ( ! next ) {
660- yield * halt ( err )
661- return
662- }
663- const key = `${ next . providerID } /${ next . modelID } `
664- triedFallbacks . add ( key )
665- yield * Effect . logInfo ( "model fallback" , { from : `${ input . model . providerID } /${ input . model . id } ` , to : key } )
666- const fallbackModel = yield * provider . getModel (
667- ProviderV2 . ID . make ( next . providerID ) ,
668- ModelV2 . ID . make ( next . modelID ) ,
669- ) . pipe (
670- Effect . catch ( ( e ) => Effect . gen ( function * ( ) {
671- yield * Effect . logWarning ( "fallback model not found" , { target : key , error : errorMessage ( e ) } )
672- return yield * Effect . fail ( err )
673- } ) ) ,
674- )
675- const fallbackInput = { ...streamInput , model : fallbackModel }
676- yield * Effect . gen ( function * ( ) {
677- ctx . currentText = undefined
678- ctx . reasoningMap = { }
679- ctx . toolcalls = { }
680- ctx . needsCompaction = false
681- yield * status . set ( ctx . sessionID , { type : "busy" } )
682- const stream = llm . stream ( fallbackInput )
683- yield * stream . pipe (
684- Stream . tap ( ( event ) => handleEvent ( event ) ) ,
685- Stream . takeUntil ( ( ) => ctx . needsCompaction ) ,
686- Stream . runDrain ,
687- )
688- } ) . pipe (
689- Effect . catchCauseIf (
690- ( cause ) => ! Cause . hasInterruptsOnly ( cause ) ,
691- ( cause ) => Effect . fail ( Cause . squash ( cause ) ) ,
692- ) ,
693- Effect . retry (
694- SessionRetry . policy ( {
695- provider : next . providerID ,
696- parse,
697- set : ( info ) => {
698- return status . set ( ctx . sessionID , {
699- type : "retry" ,
700- attempt : info . attempt ,
701- message : info . message ,
702- action : info . action ,
703- next : info . next ,
704- } )
705- } ,
706- } ) ,
707- ) ,
708- Effect . catch ( halt ) ,
709- )
710- } )
711-
712641 const process = Effect . fn ( "SessionProcessor.process" ) ( function * ( streamInput : LLM . StreamInput ) {
713642 yield * Effect . logInfo ( "process" , {
714643 "session.id" : input . sessionID ,
@@ -757,7 +686,7 @@ const layer = Layer.effect(
757686 } ,
758687 } ) ,
759688 ) ,
760- Effect . catch ( ( err ) => Effect . gen ( function * ( ) { yield * attemptFallback ( streamInput , err ) } ) . pipe ( Effect . catch ( halt ) ) ) ,
689+ Effect . catch ( halt ) ,
761690 Effect . ensuring ( cleanup ( ) ) ,
762691 )
763692
@@ -797,7 +726,6 @@ export const node = LayerNode.make({
797726 Image . node ,
798727 EventV2Bridge . node ,
799728 Database . node ,
800- Provider . node ,
801729 ] ,
802730} )
803731
0 commit comments