Skip to content

refactor(extras): drop ai input checks - #937

Merged
ParidelPooya merged 1 commit into
mainfrom
refactor/extras-ai-simplify
Nov 17, 2026
Merged

ParidelPooya merged 1 commit into
mainfrom
refactor/extras-ai-simplify

Conversation

@ParidelPooya

Copy link
Copy Markdown
Contributor

Why

context.step does not validate developer input, guard misuse, or handle the invocation deadline. It returns the error, and the developer retries or handles it. The experimental ai operations did all three. This PR makes them match context.step. It also fixes the remaining items of #934 that still apply.

Removed vs Kept

Removed Kept
Pre-step checks of question, choices, and scale (validate_question, validate_options, validate_scale) DeciderInvalidResponseError for 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 options
MAX_CLASSIFY_OPTIONS and MAX_SCORE_LEVELS and their exports. The docs now state the model's limits instead. LlmMaxTokensError and LlmStoppedError
The early serialize_input call. The input is serialized once, inside the step. DeciderError.status and LlmStoppedError.stop_reason, merged into data
decider() guards: headers with a transport, both endpoint and transport, threshold range. The threshold default stays 0.5. Registration of every error class, and the rebuild of the AiError class in run_step
remaining_seconds, call_before_deadline and its thread, INVOCATION_RESERVE_SECONDS, AiTimeoutError (class, registry entry, export) The AgentCore, SageMaker, Lambda, and HTTP transports
default_ai_retry_strategy and its export. The step uses the SDK default unless the caller passes retry_strategy. Endpoint safety: no credentials in the URL, no redirects, query left out of error messages
The decider() error when there is no transport, no endpoint, and no STRANDS_DECIDER_ENDPOINT

The decider() guard decision:

  • "Only one of endpoint and transport" is removed. decider() still works when both are set: the transport takes precedence, and the docs say so.
  • "Needs a transport or an endpoint" is kept. Without either one, decider() has nowhere to send the request. So it cannot create a usable operation.

#934 status

Item Status
Require core >=3.0.0 Already on main (>=3.0.0,<4, from #929). Core 3.0.0 on PyPI has StepConfig.sub_type. No change.
Timeout retry delay inside the reserve Moot. The reserve and AiTimeoutError are removed.
http.client.HTTPException on a body read Fixed. Both reads raise DeciderError. An error response keeps its HTTP status. Tests cover a truncated 200 and a truncated 503.
Context variables in the request thread Moot. The thread is removed. The transport runs in the step's thread.
Unusable deadline readings Moot. The deadline is not read.
ask with no stopReason Fixed. It raises LlmStoppedError, with and without content. Tests cover both.
Double serialization of the input Fixed. A test counts one iteration of the input.
Minimum function timeout in the docs Moot. There is no reserve.
End-to-end test under tests/e2e Not done. The extras package has no tests/e2e setup. 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, and MAX_SCORE_LEVELS are no longer exported.
  • An invalid argument no longer raises TypeError or ValueError before the step. The step sends the request, and the model's or the service's error comes back from the step. An input that json.dumps cannot encode fails the step with StepError.
  • The default retry strategy is the SDK's step default: 6 attempts for every error. Pass retry_strategy= to stop on errors that repeat, such as status 422.
  • decider(transport=..., endpoint=...) and decider(transport=..., headers=...) no longer raise. The transport is used.
  • A step no longer stops waiting 10 seconds before the invocation ends. A transport that can hang needs its own timeout.

Testing

  • pytest -q -n 8 -p no:cacheprovider packages/aws-durable-execution-sdk-python-extras/tests: 599 passed (103 in tests/ai).
  • mypy on the extras src and tests: no issues.
  • hatch fmt --check in the extras package: passes.
  • python .github/scripts/lintcommit.py --range origin/main..HEAD: passes.

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
@ParidelPooya
ParidelPooya deployed to ai-pr-review-runtime November 16, 2026 21:27 — with GitHub Actions Active
@ParidelPooya
ParidelPooya deployed to ai-pr-review-runtime November 16, 2026 21:28 — with GitHub Actions Active
@github-actions

Copy link
Copy Markdown
Contributor

Codex AI review

Four approach findings:

  • packages/aws-durable-execution-sdk-python-extras/src/aws_durable_execution_sdk_python_extras/ai/decider.py:340: incomplete API design and decision record.
  • packages/aws-durable-execution-sdk-python-extras/src/aws_durable_execution_sdk_python_extras/ai/_shared.py:84: missing required integration coverage.
  • packages/aws-durable-execution-sdk-python-extras/docs/ai.md:102: unverified service-validation assumption.
  • packages/aws-durable-execution-sdk-python-extras/tests/ai/llm_test.py:208: undocumented expectation changes.

Static review only; tests were not executed.

Reviewed commit 2f9741a916b582e7febbe18a3caef2ad4f01347e. Workflow run

@ParidelPooya
ParidelPooya merged commit 84759fa into main Nov 17, 2026
27 checks passed
@ParidelPooya
ParidelPooya deleted the refactor/extras-ai-simplify branch November 17, 2026 18:52

This branch was successfully deployed

1 active deployment
ai-pr-review-runtime — 2f9741a9 Deployed Nov 16, 2026 by ParidelPooya via ai-pr-review / Codex review / Generate Codex review #3155
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants