fix: keep conda and virtualenv activation across session restore - #2367
fix: keep conda and virtualenv activation across session restore#2367happysnehal111-del wants to merge 1 commit into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (12)
🚧 Files skipped from review as they are similar to previous changes (12)
📝 WalkthroughWalkthroughThe change detects Conda and venv activations across platforms. Pane snapshots store activation metadata. Workspace capture, terminal restoration, and deferred agent resume preserve this state and apply its environment variables to launches. ChangesVirtual environment persistence
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant Tab
participant TerminalRuntime
participant PaneRuntime
participant PlatformProcessReader
participant Snapshot
participant Restore
participant Terminal
Tab->>TerminalRuntime: request foreground_virtual_env
TerminalRuntime->>PaneRuntime: request foreground_virtual_env
PaneRuntime->>PlatformProcessReader: read process environment
PlatformProcessReader-->>PaneRuntime: return VirtualEnvActivation
PaneRuntime-->>TerminalRuntime: return activation
TerminalRuntime-->>Tab: return activation
Tab->>Snapshot: capture activation
Snapshot-->>Restore: provide saved activation
Restore->>Terminal: apply activation during launch
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 5
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 19bca225-41b0-4f49-8c9d-8d125c9b9874
📒 Files selected for processing (12)
src/app/agent_resume.rssrc/pane.rssrc/persist/restore.rssrc/persist/snapshot.rssrc/platform/fallback.rssrc/platform/linux.rssrc/platform/macos.rssrc/platform/mod.rssrc/platform/windows.rssrc/terminal/runtime.rssrc/terminal/state.rssrc/workspace/tab.rs
A pane working inside an activated conda environment or virtualenv came back from restore on the shell's default environment, so an agent resumed into that pane ran against the wrong interpreter. Panes now record the activation prefix alongside their cwd, and restore hands it back to the shell it spawns, including the deferred spawn that resumes an agent. PATH is rebuilt from the prefix instead of replayed from the snapshot so a restored pane follows the current machine, and an environment that has been removed since the save is dropped rather than re-entered. The restored shell re-runs the user's rc files, so conda's automatic base activation is suppressed for it; otherwise base lands on PATH ahead of whatever was restored.
7d17ab3 to
e6308ed
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
Greptile SummaryThis PR persists detected conda and virtualenv activation metadata and reconstructs the corresponding launch environment during pane restoration and deferred agent resume.
Confidence Score: 5/5The PR appears safe to merge, with no concrete blocking or independently actionable non-blocking defects identified. The snapshot field is optional and backward-compatible, missing or deleted environments degrade to the inherited environment, and activation reconstruction is consistently applied to both cold restore and deferred agent resume paths.
|
| Filename | Overview |
|---|---|
| src/platform/mod.rs | Defines activation parsing and reconstructs platform-specific PATH and environment variables for restored panes. |
| src/pane.rs | Detects activation from the pane’s foreground process-group leader without adding a blocking PTY actor round trip. |
| src/persist/snapshot.rs | Adds backward-compatible optional activation metadata and captures live or restored activation state. |
| src/persist/restore.rs | Validates saved prefixes, applies reconstructed launch variables, and carries activation state onto restored terminals. |
| src/app/agent_resume.rs | Applies the restored interpreter environment when resuming an agent through a newly spawned shell. |
| src/platform/windows.rs | Reads virtual-environment variables from a selected process’s PEB environment block. |
| src/platform/linux.rs | Reads virtual-environment variables from the foreground process environment exposed through procfs. |
| src/platform/macos.rs | Reads virtual-environment variables from the foreground process environment exposed through KERN_PROCARGS2. |
Sequence Diagram
sequenceDiagram
participant Save as Session snapshot
participant Pane as Pane runtime
participant OS as Platform process API
participant Restore as Session restore
participant Shell as Restored shell
Save->>Pane: Request foreground activation
Pane->>OS: Read foreground process environment
OS-->>Pane: Environment prefix and kind
Pane-->>Save: VirtualEnvActivation
Save->>Save: Persist kind, prefix, and name
Restore->>Restore: Validate saved prefix
Restore->>Restore: Rebuild activation variables and PATH
Restore->>Shell: Spawn with PaneLaunchEnv
Restore->>Restore: Retain activation in TerminalState
Reviews (1): Last reviewed commit: "fix: keep conda and virtualenv activatio..." | Re-trigger Greptile
Problem
A pane that was working inside an activated conda environment or virtualenv comes back from a session restore on the shell's default environment. The agent resumes, but against the wrong interpreter —
python,pip, and anything else installed into the environment resolve outside it.Restore spawns the pane's shell with an empty
PaneLaunchEnv, and the snapshot has nowhere to record an activation, so there is nothing to hand back.How the environment is read
A shell mutates its own environment in place when it activates one, and that mutation is not visible from outside the process. What is visible is the environment a process was launched with, so the pane's foreground process group leader — the command the shell started — carries the activation that was in effect when it began. In the case that matters, that process is the agent.
The primitives for this were already here:
/proc/<pid>/environon Linux,KERN_PROCARGS2on macOS, and the PEB read on Windows. This adds one function per platform on top of them, and a fallback stub elsewhere.What gets stored
Only the activation prefix and its display name, not a copy of
PATH.PATHis rebuilt from the prefix on restore, so a restored pane follows the current machine rather than being pinned to whatever it looked like when the snapshot was written. Entries already on the inheritedPATHare not repeated, so repeated restores cannot grow it.PaneSnapshot.virtual_envis optional and skipped when absent, soSNAPSHOT_VERSIONstays at 3 and sessions written by this build still load on older ones.conda's automatic base activation
Restored panes come back as interactive login shells, so they re-run the user's rc files, and conda's init hook activates
baseby default. That runs after the environment is handed in and replaces it. It shadows a restored virtualenv too, becausebaselands ahead of it onPATH.CONDA_AUTO_ACTIVATEandCONDA_AUTO_ACTIVATE_BASEare therefore set tofalsefor restored panes that have a recorded environment — both spellings, since conda renamed the setting in 25.x. Panes without a recorded environment are untouched and still auto-activatebaseas before.Testing
cargo fmt --check,cargo clippy --all-targets -- -D warnings, and the cross-target Windows clippy fromjust windows-lintare clean.cargo nextest runpasses except for three tests that fail identically on an unmodifiedmasteron this machine:live_handoff_keeps_agent_started_pane_after_agent_exits,live_handoff_keeps_unmanaged_agent_name_bound_to_saved_session, andpane_info_and_subscriptions_expose_done_agent_status.venvcome back with the right prefix and withpythonresolving into the environment.