cbd8de8ad6
The function _persist_live_session_system_prompt runs on the RPC dispatcher thread. A model switch calls it. On that thread the _SESSION_CWD contextvar is not set. Because of this, resolve_agent_cwd() falls back to the process TERMINAL_CWD value. The desktop pins TERMINAL_CWD to the home directory. The rebuilt prompt then records the home directory as the working directory. The wrong prompt persists to the session database. Later turns restore the stored bytes without change, because the turn prologue rebuilds the prompt only when the cache is empty. The wrong line never heals. The terminal tool is not affected, because it reads the per-session cwd record. The desktop composer sends a model switch before the first turn when its model differs from the config default. Because of this, a new project session can show the wrong working directory for its full life. Fix: bind the session context around the rebuild, in the same way the function already binds the profile home for issue #50233. The test drives the real function from a bare thread and asserts the persisted prompt carries the session cwd.