Skip to content

Commit 0b0875c

Browse files
mscolnickCopilot
andauthored
fix: only show previous session when in edit mode (#7737)
We previously would show the previous session in Run, when we only want to do this in edit mode. Supersedes #7619 --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 20bd3ac commit 0b0875c

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

marimo/_session/session.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@ def create(
116116
*(extensions or []),
117117
LoggingExtension(),
118118
HeartbeatExtension(),
119-
CachingExtension(enabled=not auto_instantiate),
119+
CachingExtension(
120+
enabled=not auto_instantiate and mode == SessionMode.EDIT
121+
),
120122
NotificationListenerExtension(
121123
kernel_manager=kernel_manager, queue_manager=queue_manager
122124
),

tests/_server/test_sessions.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,3 +1066,53 @@ def test_session_with_script_config_overrides(
10661066

10671067
# Cleanup
10681068
session.close()
1069+
1070+
1071+
@save_and_restore_main
1072+
async def test_caching_enabled_only_in_edit_mode() -> None:
1073+
"""Test that caching is only enabled in EDIT mode, not RUN mode."""
1074+
from marimo._session.extensions.extensions import CachingExtension
1075+
1076+
session_consumer = MagicMock()
1077+
session_consumer.connection_state.return_value = ConnectionState.OPEN
1078+
1079+
def create_session(mode: SessionMode, auto_instantiate: bool) -> Session:
1080+
return SessionImpl.create(
1081+
initialization_id="test_session",
1082+
session_consumer=session_consumer,
1083+
mode=mode,
1084+
app_metadata=app_metadata,
1085+
app_file_manager=AppFileManager.from_app(InternalApp(App())),
1086+
config_manager=get_default_config_manager(current_path=None),
1087+
virtual_files_supported=True,
1088+
redirect_console_to_browser=False,
1089+
ttl_seconds=None,
1090+
auto_instantiate=auto_instantiate,
1091+
)
1092+
1093+
def find_caching_extension(session: Session) -> CachingExtension:
1094+
extension = [
1095+
ext
1096+
for ext in session.extensions
1097+
if isinstance(ext, CachingExtension)
1098+
]
1099+
assert len(extension) == 1
1100+
return extension[0]
1101+
1102+
# Test 1: EDIT mode with auto_instantiate=False -> caching enabled
1103+
session_edit = create_session(SessionMode.EDIT, False)
1104+
1105+
# Find the CachingExtension
1106+
caching_extension_edit = find_caching_extension(session_edit)
1107+
assert caching_extension_edit.enabled is True
1108+
1109+
# Test 2: RUN mode with auto_instantiate=True -> caching disabled
1110+
session_run = create_session(SessionMode.RUN, True)
1111+
1112+
# Find the CachingExtension
1113+
caching_extension_run = find_caching_extension(session_run)
1114+
assert caching_extension_run.enabled is False
1115+
1116+
# Cleanup
1117+
session_edit.close()
1118+
session_run.close()

0 commit comments

Comments
 (0)