Skip to content

Commit

Permalink
feat: Add codejail darklaunch toggle.
Browse files Browse the repository at this point in the history
This adds a toggle for running codejail in both remote
and local configurations for testing purposes.

edx/edx-arch-experiments#895
  • Loading branch information
dianakhuang committed Mar 3, 2025
1 parent fd3a106 commit 8d980fb
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
20 changes: 20 additions & 0 deletions xmodule/capa/safe_exec/remote_exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,31 @@
"ENABLE_CODEJAIL_REST_SERVICE", default=False, module_name=__name__
)

# .. toggle_name: ENABLE_CODEJAIL_DARKLAUNCH
# .. toggle_implementation: SettingToggle
# .. toggle_default: False
# .. toggle_description: Turn on to send requests to both the codejail service and the installed codejail library for
# testing and evaluation purposes.
# .. toggle_warning: This toggle will only behave as expected when ENABLE_CODEJAIL_REST_SERVICE is not enabled and when
# CODE_JAIL_REST_SERVICE_REMOTE_EXEC, CODE_JAIL_REST_SERVICE_HOST, CODE_JAIL_REST_SERVICE_READ_TIMEOUT,
# and CODE_JAIL_REST_SERVICE_CONNECT_TIMEOUT are configured.
# .. toggle_use_cases: temporary
# .. toggle_creation_date: 2025-04-03
# .. toggle_target_removal_date: 2025-05-01
ENABLE_CODEJAIL_DARKLAUNCH = SettingToggle(
"ENABLE_CODEJAIL_DARKLAUNCH", default=False, module_name=__name__
)


def is_codejail_rest_service_enabled():
return ENABLE_CODEJAIL_REST_SERVICE.is_enabled()


# This toggle assumes that ENABLE_CODEJAIL_REST_SERVICE is not enabled.
def is_codejail_in_darklaunch():
return ENABLE_CODEJAIL_DARKLAUNCH.is_enabled()


def get_remote_exec(*args, **kwargs):
"""Get remote exec function based on setting and executes it."""
remote_exec_function_name = settings.CODE_JAIL_REST_SERVICE_REMOTE_EXEC
Expand Down
17 changes: 16 additions & 1 deletion xmodule/capa/safe_exec/safe_exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from edx_django_utils.monitoring import function_trace

from . import lazymod
from .remote_exec import is_codejail_rest_service_enabled, get_remote_exec
from .remote_exec import is_codejail_rest_service_enabled, is_codejail_in_darklaunch, get_remote_exec

# Establish the Python environment for Capa.
# Capa assumes float-friendly division always.
Expand Down Expand Up @@ -155,6 +155,21 @@ def safe_exec(
emsg, exception = get_remote_exec(data)

else:
# Run the code in both the remote codejail service as well as the local codejail
# when in darklaunch mode.
if is_codejail_in_darklaunch():
data = {
"code": code_prolog + LAZY_IMPORTS + code,
"globals_dict": globals_dict,
"python_path": python_path,
"limit_overrides_context": limit_overrides_context,
"slug": slug,
"unsafely": unsafely,
"extra_files": extra_files,
}

emsg, exception = get_remote_exec(data)

# Decide which code executor to use.
if unsafely:
exec_fn = codejail_not_safe_exec
Expand Down

0 comments on commit 8d980fb

Please sign in to comment.