I think you may be confusing two things. $_SESSION = 'foo'; this statement simply assigns a value to the $_SESSION superglobal. The superglobal is in memory at this point. sess_write() is called by PHP's built-in session handling code. It is the very last thing called before PHP exits. Within this function, Drupal updates the appropriate database row with the value of $_SESSION. So the sequence you gave is correct.
Is sess_write() called by the same PHP process that handles page requests?
I'm working with dado to debug node_import.module (see http://drupal.org/node/63581). node_import.module uses a $_SESSION variable to control the workflow state, which is something I've not seen often.
Simply put, the workflow progresses normally for some people (e.g. dado) and not for others (e.g. me). For me, some variables in $_SESSION are effectively not updated. I say "effectively" because $_SESSION is written twice. The second write uses old values.
At one point, I have the following debugging statements: <?php
watchdog('debug', 'Before'); $_SESSION['node_import'] = $edit; // NOTE: sess_write() calls watchdog('debug', 'Writing'). watchdog('debug', 'After');
?>
The logs consistently show, in reverse chronological order: Writing After Before
What's going on?
Nic