Repository navigation
refactor(extras): drop ai input checks - #937
Merged
Merged
Conversation
The core step does not validate developer input, guard misuse, or handle the invocation deadline. The ai operations now match it. The step returns every error, and the developer retries or handles it. Removed: - Pre-step checks of the question, choices, and scale, and the MAX_CLASSIFY_OPTIONS and MAX_SCORE_LEVELS exports. The input is serialized once, inside the step. - The decider() guards for headers with a transport, for both endpoint and transport, and for the threshold range. A transport now takes precedence over an endpoint. - The deadline thread, the 10-second reserve, and AiTimeoutError. - default_ai_retry_strategy. The step uses the SDK default unless the caller passes retry_strategy. Fixed: - The HTTP transport turns http.client.HTTPException from either body read into DeciderError, and keeps the HTTP status when it has one. - llm().ask raises LlmStoppedError when the reply has no stopReason. Refs #934
Contributor
Codex AI reviewFour approach findings:
Static review only; tests were not executed. Reviewed commit |
yaythomas
approved these changes
Nov 17, 2026
1 task done
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
context.stepdoes not validate developer input, guard misuse, or handle the invocation deadline. It returns the error, and the developer retries or handles it. The experimentalaioperations did all three. This PR makes them matchcontext.step. It also fixes the remaining items of #934 that still apply.Removed vs Kept
question,choices, andscale(validate_question,validate_options,validate_scale)DeciderInvalidResponseErrorfor an unusable reply: not JSON, no answers, wrong type, not finite, probability outside 0 to 1 (0.01 clamp), score outside the scale, a choice that is not a string or not one of the optionsMAX_CLASSIFY_OPTIONSandMAX_SCORE_LEVELSand their exports. The docs now state the model's limits instead.LlmMaxTokensErrorandLlmStoppedErrorserialize_inputcall. The input is serialized once, inside the step.DeciderError.statusandLlmStoppedError.stop_reason, merged intodatadecider()guards: headers with a transport, both endpoint and transport, threshold range. The threshold default stays 0.5.AiErrorclass inrun_stepremaining_seconds,call_before_deadlineand its thread,INVOCATION_RESERVE_SECONDS,AiTimeoutError(class, registry entry, export)default_ai_retry_strategyand its export. The step uses the SDK default unless the caller passesretry_strategy.decider()error when there is no transport, no endpoint, and noSTRANDS_DECIDER_ENDPOINTThe
decider()guard decision:decider()still works when both are set: the transport takes precedence, and the docs say so.decider()has nowhere to send the request. So it cannot create a usable operation.#934 status
>=3.0.0main(>=3.0.0,<4, from #929). Core 3.0.0 on PyPI hasStepConfig.sub_type. No change.AiTimeoutErrorare removed.http.client.HTTPExceptionon a body readDeciderError. An error response keeps its HTTP status. Tests cover a truncated 200 and a truncated 503.askwith nostopReasonLlmStoppedError, with and without content. Tests cover both.tests/e2etests/e2esetup. The local-runner tests already run the public operations through replay with fake transports and clients.So this PR uses
Refs #934. The end-to-end test remains.Breaking changes
The module is experimental, so these changes are allowed. Callers can see them:
AiTimeoutError,default_ai_retry_strategy,MAX_CLASSIFY_OPTIONS, andMAX_SCORE_LEVELSare no longer exported.TypeErrororValueErrorbefore the step. The step sends the request, and the model's or the service's error comes back from the step. An input thatjson.dumpscannot encode fails the step withStepError.retry_strategy=to stop on errors that repeat, such as status 422.decider(transport=..., endpoint=...)anddecider(transport=..., headers=...)no longer raise. The transport is used.Testing
pytest -q -n 8 -p no:cacheprovider packages/aws-durable-execution-sdk-python-extras/tests: 599 passed (103 intests/ai).mypyon the extrassrcandtests: no issues.hatch fmt --checkin the extras package: passes.python .github/scripts/lintcommit.py --range origin/main..HEAD: passes.