Skip to content

Commit 1c95d6e

Browse files
committed
refactor: standardize attempt counting
Remove Logger's +1 transformation and have all code pass current attempt (1, 2, 3...) consistently throughout the codebase. Previously, Logger added +1 internally, creating confusion about whether code should pass 'current attempt' or 'checkpointed attempt'. This standardization removes the hidden transformation. Changes: - Remove +1 from Logger.from_log_info() (logger.py line 75) - Update StepContext to pass current attempt by adding +1 (step.py lines 205-208) - Update logger tests to expect current attempt values This ensures all components use the same convention: current attempt = checkpointed attempts + 1, with no hidden transformations.
1 parent 9d2a859 commit 1c95d6e

3 files changed

Lines changed: 6 additions & 5 deletions

File tree

src/aws_durable_execution_sdk_python/logger.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def from_log_info(cls, logger: LoggerInterface, info: LogInfo) -> Logger:
7272
# Use 'operation_name' instead of 'name' as key because the stdlib LogRecord internally reserved 'name' parameter
7373
extra["operationName"] = info.name
7474
if info.attempt is not None:
75-
extra["attempt"] = info.attempt + 1
75+
extra["attempt"] = info.attempt
7676
if info.operation_id:
7777
extra["operationId"] = info.operation_id
7878
return cls(

src/aws_durable_execution_sdk_python/operation/step.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,10 @@ def execute(self, checkpointed_result: CheckpointedResult) -> T:
202202
ExecutionError: For fatal errors that should not be retried
203203
May raise other exceptions that will be handled by retry_handler
204204
"""
205-
attempt: int = 0
205+
# Get current attempt - checkpointed attempts + 1
206+
attempt: int = 1
206207
if checkpointed_result.operation and checkpointed_result.operation.step_details:
207-
attempt = checkpointed_result.operation.step_details.attempt
208+
attempt = checkpointed_result.operation.step_details.attempt + 1
208209

209210
step_context: StepContext = StepContext(
210211
logger=self.context_logger.with_log_info(

tests/logger_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def test_logger_from_log_info_full():
177177
"parentId": "parent123",
178178
"operationId": "op123",
179179
"operationName": "test_name",
180-
"attempt": 6,
180+
"attempt": 5,
181181
}
182182
assert logger._default_extra == expected_extra # noqa: SLF001
183183
assert logger._logger is mock_logger # noqa: SLF001
@@ -202,7 +202,7 @@ def test_logger_from_log_info_partial_fields():
202202
# Test with attempt but no parent_id or name
203203
log_info = LogInfo(EXECUTION_STATE, None, None, None, 5)
204204
logger = Logger.from_log_info(mock_logger, log_info)
205-
expected_extra = {"executionArn": "arn:aws:test", "attempt": 6}
205+
expected_extra = {"executionArn": "arn:aws:test", "attempt": 5}
206206
assert logger._default_extra == expected_extra # noqa: SLF001
207207

208208

0 commit comments

Comments
 (0)