You can see what is going on by setting $FrontEndSession Evaluator->"LinkSnooper".
Create a notebook (A) with two cells and evaluate them:
SetOptions[$FrontEndSession, Evaluator -> "LinkSnooper"]
$Context
Create another (B) one with:
SetOptions[EvaluationNotebook[], CellContext -> Notebook]
$Context
Let's clear LinkSnooper's console and check what happens when we evaluate $Context in (A) and (B). Here is an output (reduced to a relevant part, also FE/Kernel communication expressions names have "*Paclet" pattern (e.g. EvaluatePaclet), I dropped Paclet for a readability)
$Context
"Global`"
FE -> K: Evaluate[FrontEnd`Private`SwitchCellContext["Global`", "Main"]]
FE <- K: Return["Notebook$$18$756624`"]
FE -> K: Evaluate[ToExpression["FE`SetEvaluationNotebookFileName[None];"]]
FE -> K: EnterExpression[MakeExpression[BoxData["$Context"], StandardForm]]
FE <- K: ReturnExpression[BoxData["\"Global`\"", StandardForm]]
$Context
"Notebook$$18$756624`"
FE -> K: Evaluate[FrontEnd`Private`SwitchCellContext["Notebook$$18$756624`", "Main"]]
FE <- K: Return["Global`"]
FE -> K: Evaluate[ToExpression["FE`SetEvaluationNotebookFileName[None];"]]
FE -> K: EnterExpression[MakeExpression[BoxData["$Context"], StandardForm]]
FE <- K: ReturnExpression[BoxData["\"Notebook$$18$756624`\"", StandardForm]]
Repeating last evaluation shows no sign of SwitchCellContext, which probably means that the FrontEnd knows from where the last input was read and in case of change it asks the Kernel to SwitchCellContext[ to-notebookCellContex, on-kernel].
Which is just a quck guess from a short test. Any insight is appreciated, edit or answer if you want to add someyhing.
$Contextneeds to be updated. It will not appear in the output asSet[$Context, ...]. – ihojnicki Jul 13 '16 at 13:07$FrontEndSession'sEvaluator. Unless someone is willing to authoritatively answer I will do that later. – Kuba Jul 13 '16 at 13:15FrontEnd`Private`SwitchCellContext, as you can runFrontEnd`Private`SwitchCellContextEvaluate["asd`", ToExpression@"zzz"]to run stuff in that new context. This seems to be like the case of https://mathematica.stackexchange.com/questions/108850/what-is-the-equivalent-of-modulenumber-for-dynamicmodule – b3m2a1 Dec 27 '17 at 19:42