feat: Run remote codejail even if unexpected exception in local safe_exec
During dark launch of remote codejail, we want to ensure we always run both
local and remote execution -- otherwise we're missing data for the remote
side in an important situation.
This will help answer the question of whether the unexpected exception
happens on both sides, even though it may not look exactly the same due to
differences in how unexpected errors are handled.
An example input that provokes this in unsafe execution mode is
`raise BaseException("hi")`; in safe execution mode, printing to
`sys.__stdout__` should also produce an appropriate error.
This commit is contained in:
@@ -159,6 +159,8 @@ def safe_exec(
|
||||
raise SafeExecException(emsg)
|
||||
return
|
||||
|
||||
cacheable = True # unless we get an unexpected error
|
||||
|
||||
# Create the complete code we'll run.
|
||||
code_prolog = CODE_PROLOG % random_seed
|
||||
|
||||
@@ -196,11 +198,17 @@ def safe_exec(
|
||||
limit_overrides_context=limit_overrides_context,
|
||||
slug=slug,
|
||||
)
|
||||
except SafeExecException as e:
|
||||
except BaseException as e:
|
||||
# Saving SafeExecException e in exception to be used later.
|
||||
exception = e
|
||||
emsg = str(e)
|
||||
if not isinstance(exception, SafeExecException):
|
||||
# Something unexpected happened, so don't cache this evaluation.
|
||||
# (We may decide to cache these in the future as well; this is just
|
||||
# preserving existing behavior during a refactor of error handling.)
|
||||
cacheable = False
|
||||
else:
|
||||
exception = None
|
||||
emsg = None
|
||||
|
||||
# Run the code in both the remote codejail service as well as the local codejail
|
||||
@@ -235,10 +243,10 @@ def safe_exec(
|
||||
|
||||
# Put the result back in the cache. This is complicated by the fact that
|
||||
# the globals dict might not be entirely serializable.
|
||||
if cache:
|
||||
if cache and cacheable:
|
||||
cleaned_results = json_safe(globals_dict)
|
||||
cache.set(key, (emsg, cleaned_results))
|
||||
|
||||
# If an exception happened, raise it now.
|
||||
if emsg:
|
||||
if exception:
|
||||
raise exception
|
||||
|
||||
Reference in New Issue
Block a user