@@ -39,6 +39,8 @@ type RootProbePlan = {
3939
4040type RootMovePhase = 'multipv' | 'screen' | 'deep' | 'ground-truth'
4141type CandidateSelectionSource = 'sf-top' | 'maia-95' | 'both'
42+ const MAX_MAIA_DEEPEN_MOVES = 4
43+ const MAIA_MID_DEPTH = 14
4244
4345type AnalysisRunContext = {
4446 positionId : string
@@ -755,6 +757,77 @@ class Engine {
755757 runContext . kSf > 0 ? runContext . kSf : 4 ,
756758 ) ,
757759 )
760+ const maiaTopMoves = runContext . maiaCandidateMoves . slice (
761+ 0 ,
762+ MAX_MAIA_DEEPEN_MOVES ,
763+ )
764+ const maiaMidDepth = Math . min ( MAIA_MID_DEPTH , targetDepth )
765+
766+ if ( maiaMidDepth > plan . screeningDepth ) {
767+ for ( const move of maiaTopMoves ) {
768+ if ( ! this . isActiveRun ( runContext . positionId ) ) {
769+ return
770+ }
771+
772+ if ( ! rootScores [ move ] ) {
773+ continue
774+ }
775+
776+ markSelectionSource ( move , 'maia-95' )
777+ const current = rootScores [ move ]
778+ if ( current && current . depth >= maiaMidDepth ) {
779+ continue
780+ }
781+
782+ const t0 = Date . now ( )
783+ const deepProbe = await this . runRootSearchWithRetry (
784+ runContext ,
785+ maiaMidDepth ,
786+ move ,
787+ )
788+ phaseTimesMs . deepening += Date . now ( ) - t0
789+ if ( ! deepProbe ) {
790+ continue
791+ }
792+
793+ rootScores [ move ] = {
794+ cp : deepProbe . cp ,
795+ depth : Math . max ( 1 , Math . min ( maiaMidDepth , deepProbe . depth ) ) ,
796+ mateIn : deepProbe . mateIn ,
797+ }
798+ movePhases [ move ] = 'deep'
799+ deepenedMoves . add ( move )
800+
801+ const maiaMidEval = this . buildEvaluationFromRootScores (
802+ maiaMidDepth ,
803+ rootScores ,
804+ runContext . fen ,
805+ )
806+ this . attachDiagnostics ( maiaMidEval , {
807+ runContext,
808+ strategy : 'staged-root-probe' ,
809+ targetDepth,
810+ legalMoveCount : runContext . legalMoveCount ,
811+ phaseTimesMs,
812+ rootScores,
813+ movePhases,
814+ moveSelectionSources,
815+ moveCounts : {
816+ screened : runContext . legalMoveCount ,
817+ deepened : deepenedMoves . size ,
818+ finalAtTargetDepth : Object . values ( rootScores ) . filter (
819+ ( score ) => score . depth >= targetDepth ,
820+ ) . length ,
821+ } ,
822+ } )
823+ this . maybePublishDiagnostics (
824+ maiaMidEval ,
825+ false ,
826+ runContext . diagnosticsToConsole ,
827+ )
828+ yield maiaMidEval
829+ }
830+ }
758831
759832 for await ( const multipvSnapshot of this . streamMultiPvSnapshots (
760833 runContext ,
@@ -808,7 +881,7 @@ class Engine {
808881 yield streamingEval
809882 }
810883
811- for ( const move of runContext . maiaCandidateMoves ) {
884+ for ( const move of maiaTopMoves ) {
812885 if ( ! this . isActiveRun ( runContext . positionId ) ) {
813886 return
814887 }
0 commit comments