Fail a `CodeMode` run when a DBOS replay diverges inside `run_code`, and drop the elapsed-time limit under every durable engine
Merged
AD
6d ago+438+438+012345678901234567890123456789-74-74-01234567890123456789
- Closes #12539
Why we make these changes
Under DBOSDurability and AWSLambdaDurability, a recovered execution could succeed with wrong results when tool calls came from Code Mode's run_code:
- DBOS raises
DBOSUnexpectedStepError, and the AWS Lambda SDK (2.0 and later)NonDeterministicExecutionError, to fail a replay that diverged from its recorded steps. Code Mode delivered it into the sandbox, so a snippet'stry/excepthid it, and an uncaught one became a model retry. - The elapsed-time limit was dropped only under Temporal. DBOS and Lambda replay
run_codetoo, so a snippet that hit the limit on one side of a crash called its tools in another order, and a call received another call's saved result.
Part 2 follows the maintainer comment on the issue: use in_durable_execution(ctx) for every engine. That comment also asks for crash-and-replay tests on DBOS and Lambda; both are here.
New public surface
DurabilityEngineSpec.nondeterminism_error_types, next tocancellation_error_types. Defaults to(). DBOS sets(DBOSUnexpectedStepError,); AWS Lambda sets(NonDeterministicExecutionError,), which exists at the>=1.7.0floor but is raised only by SDK 2.0 and later.- Other engines keep
()until a divergence reachingrun_codeis reproduced on them: Temporal, Prefect, Azure Durable Task, Absurd, pgtask and render were not reproduced here.
User-visible behavior
code_mode/_toolset.py :: CodeModeToolset._execute_code()
└─ _monty_exec.py :: MontyExecutor.run()
└─ _await_external() / _wrap_gathered() / _close_pending()
- └─ DBOSUnexpectedStepError raised inside the snippet
+ └─ DBOSUnexpectedStepError ends the feed
└─ _feed_failure_retry()
- └─ ModelRetry
+ └─ re-raised: the workflow fails, as for a direct tool call
Verification
test_dbos.py: crash and resume a DBOS workflow whose replay diverges (parallel and sequential tools); the time limit is off in a workflow; outside a workflow the snippet still catches the error.test_reraise.py: awaited, gathered, sequential and never-awaited calls, plus cancellation is kept.test_aws_lambda.pytest_a_diverging_step_inside_run_code_fails_the_execution: the test fake now raises the SDK'sNonDeterministicExecutionErroron a name mismatch, as SDK 2.0'svalidate_checkpointdoes. Without the spec field the snippet catches it and the replay returns the first run's answer.- The issue's SIGKILL
repro.pyon this branch:codeandcode_trynow fail likenative;timeout(paused) is now correct.
What changes for existing users
[!WARNING]
Compatibility impact, permitted as a bug fix under the version policy. Only durable runs change:
- Under DBOS and AWS Lambda, a replay that diverges inside
run_code now fails the run instead of returning a result built from another step's checkpoint. Migration: deploy changed agent code as a new DBOS application version or Lambda published version, as the engine docs already require.
CodeMode's max_duration_seconds is now off under every durable engine, not only Temporal, including an explicit override. Migration: move time-bounded work into a tool, or use a remote pool's request_timeout as the wall-clock bound. Monty has no replay-safe CPU budget to use instead.
Follow-ups (not reproduced here, to be filed): DBOS's DBOSStepNondeterminismError (absent from the dbos>=2.10.0 floor), and DynamicWorkflow, which wraps sub-agent errors in RuntimeError.
Checklist
- No breaking changes in accordance with the version policy.
- Any permitted compatibility impact has a label, warning, migration and release note, and an exact API-check waiver if the gate reports it.
- PR title is fit for the release changelog.