durable-workflow 2.20.0__tar.gz → 2.21.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (246) hide show
  1. {durable_workflow-2.20.0/src/durable_workflow.egg-info → durable_workflow-2.21.1}/PKG-INFO +3 -2
  2. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/README.md +2 -1
  3. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/pyproject.toml +3 -3
  4. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/src/durable_workflow/_activity_lease.py +230 -20
  5. durable_workflow-2.21.1/src/durable_workflow/_capabilities_digest.py +104 -0
  6. durable_workflow-2.21.1/src/durable_workflow/_response_limit.py +74 -0
  7. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/src/durable_workflow/activity.py +3 -3
  8. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/src/durable_workflow/client.py +180 -46
  9. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/src/durable_workflow/errors.py +64 -5
  10. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/src/durable_workflow/sync.py +3 -0
  11. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/src/durable_workflow/worker.py +462 -22
  12. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/src/durable_workflow/workflow.py +104 -3
  13. {durable_workflow-2.20.0 → durable_workflow-2.21.1/src/durable_workflow.egg-info}/PKG-INFO +3 -2
  14. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/src/durable_workflow.egg-info/SOURCES.txt +11 -0
  15. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_activity_checkpoint.py +2 -2
  16. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_activity_heartbeat_authority.py +4 -4
  17. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_activity_lease_authority.py +86 -5
  18. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_activity_lease_worker.py +253 -2
  19. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_activity_retry_cap_cell.py +1 -1
  20. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_activity_run_closed_refusal.py +2 -2
  21. durable_workflow-2.21.1/tests/test_activity_worker_lost.py +59 -0
  22. durable_workflow-2.21.1/tests/test_capabilities_digest.py +230 -0
  23. durable_workflow-2.21.1/tests/test_capabilities_digest_unknown.py +270 -0
  24. durable_workflow-2.21.1/tests/test_parallel_failure_order.py +464 -0
  25. durable_workflow-2.21.1/tests/test_parallel_group_boundaries.py +80 -0
  26. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_parallel_member_failure_open_siblings.py +41 -0
  27. durable_workflow-2.21.1/tests/test_payload_policy_refresh.py +255 -0
  28. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_poll_failure_backoff.py +58 -16
  29. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_replay_regression_corpus.py +9 -0
  30. durable_workflow-2.21.1/tests/test_response_body_limit.py +93 -0
  31. durable_workflow-2.21.1/tests/test_result_continue_as_new.py +81 -0
  32. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_threaded_heartbeat_example.py +2 -2
  33. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_worker.py +1 -1
  34. durable_workflow-2.21.1/tests/test_worker_transient_runtime.py +391 -0
  35. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/LICENSE +0 -0
  36. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/setup.cfg +0 -0
  37. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/src/durable_workflow/__init__.py +0 -0
  38. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/src/durable_workflow/_activity_checkpoint.py +0 -0
  39. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/src/durable_workflow/_activity_process.py +0 -0
  40. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/src/durable_workflow/_avro.py +0 -0
  41. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/src/durable_workflow/_cancellation_scope.py +0 -0
  42. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/src/durable_workflow/_cancellation_scope_history.py +0 -0
  43. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/src/durable_workflow/_condition_fingerprint.py +0 -0
  44. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/src/durable_workflow/_cooperative_cancellation.py +0 -0
  45. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/src/durable_workflow/_failure_reporting.py +0 -0
  46. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/src/durable_workflow/_metric_routes.py +0 -0
  47. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/src/durable_workflow/_poll_transport.py +0 -0
  48. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/src/durable_workflow/_prepared_local_activity.py +0 -0
  49. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/src/durable_workflow/_query_task_authority.py +0 -0
  50. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/src/durable_workflow/_sticky_workflow_cache.py +0 -0
  51. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/src/durable_workflow/_typed_values.py +0 -0
  52. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/src/durable_workflow/auth_composition.py +0 -0
  53. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/src/durable_workflow/cancellation.py +0 -0
  54. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/src/durable_workflow/external_storage.py +0 -0
  55. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/src/durable_workflow/external_task_input.py +0 -0
  56. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/src/durable_workflow/external_task_result.py +0 -0
  57. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/src/durable_workflow/history_bundle_verify.py +0 -0
  58. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/src/durable_workflow/interceptors.py +0 -0
  59. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/src/durable_workflow/invocable.py +0 -0
  60. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/src/durable_workflow/metrics.py +0 -0
  61. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/src/durable_workflow/nexus.py +0 -0
  62. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/src/durable_workflow/py.typed +0 -0
  63. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/src/durable_workflow/python_conformance.py +0 -0
  64. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/src/durable_workflow/replay_clock.py +0 -0
  65. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/src/durable_workflow/replay_clock_math.py +0 -0
  66. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/src/durable_workflow/replay_conformance.py +0 -0
  67. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/src/durable_workflow/replay_verify.py +0 -0
  68. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/src/durable_workflow/retry_policy.py +0 -0
  69. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/src/durable_workflow/serializer.py +0 -0
  70. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/src/durable_workflow/server_compatibility.json +0 -0
  71. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/src/durable_workflow/telemetry.py +0 -0
  72. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/src/durable_workflow/telemetry_carrier.py +0 -0
  73. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/src/durable_workflow/testing.py +0 -0
  74. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/src/durable_workflow/worker_session.py +0 -0
  75. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/src/durable_workflow/worker_status.py +0 -0
  76. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/src/durable_workflow/workflow_updates_conformance.py +0 -0
  77. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/src/durable_workflow.egg-info/dependency_links.txt +0 -0
  78. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/src/durable_workflow.egg-info/entry_points.txt +0 -0
  79. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/src/durable_workflow.egg-info/requires.txt +0 -0
  80. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/src/durable_workflow.egg-info/top_level.txt +0 -0
  81. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_activity_acceptance_authority.py +0 -0
  82. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_activity_acceptance_consumer.py +0 -0
  83. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_activity_acceptance_entry.py +0 -0
  84. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_activity_cancellation_policies.py +0 -0
  85. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_activity_context.py +0 -0
  86. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_activity_exponential_retry.py +0 -0
  87. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_activity_identity.py +0 -0
  88. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_activity_install_inventory.py +0 -0
  89. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_activity_lease_renewal.py +0 -0
  90. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_activity_process.py +0 -0
  91. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_activity_retry_info.py +0 -0
  92. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_auth_composition.py +0 -0
  93. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_avro_value_benchmark.py +0 -0
  94. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_avro_value_protocol.py +0 -0
  95. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_business_replay_clock.py +0 -0
  96. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_business_replay_clock_child.py +0 -0
  97. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_business_replay_clock_parallel.py +0 -0
  98. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_business_replay_clock_redrive.py +0 -0
  99. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_business_replay_clock_sequence_claims.py +0 -0
  100. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_cancellation_cause.py +0 -0
  101. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_cancellation_context.py +0 -0
  102. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_cancellation_remaining_time.py +0 -0
  103. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_cancellation_scope_admission.py +0 -0
  104. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_cancellation_scope_authoring.py +0 -0
  105. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_cancellation_scope_boundary.py +0 -0
  106. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_cancellation_scope_opening.py +0 -0
  107. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_checkpointed_batch_example.py +0 -0
  108. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_child_workflow_policies.py +0 -0
  109. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_ci_checkout.py +0 -0
  110. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_ci_integration_endpoint.py +0 -0
  111. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_client.py +0 -0
  112. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_client_iterators.py +0 -0
  113. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_client_telemetry.py +0 -0
  114. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_client_timeouts.py +0 -0
  115. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_codec_regression_corpus.py +0 -0
  116. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_command_keys_acceptance.py +0 -0
  117. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_command_keys_captured_inputs.py +0 -0
  118. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_command_keys_container_ownership.py +0 -0
  119. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_command_keys_workspace.py +0 -0
  120. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_committed_cancellation_scope_descendants.py +0 -0
  121. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_committed_cancellation_scope_groups.py +0 -0
  122. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_committed_cancellation_scope_history.py +0 -0
  123. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_committed_cancellation_scope_replay.py +0 -0
  124. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_completion_size_limit.py +0 -0
  125. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_condition_fingerprint.py +0 -0
  126. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_condition_occurrence_id.py +0 -0
  127. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_condition_replay_drift.py +0 -0
  128. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_control_plane_parity_fixtures.py +0 -0
  129. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_cooperative_cancellation.py +0 -0
  130. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_cooperative_cancellation_client.py +0 -0
  131. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_cooperative_cancellation_worker.py +0 -0
  132. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_cooperative_remote_worker.py +0 -0
  133. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_docs_release_channel.py +0 -0
  134. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_docstring_cross_references.py +0 -0
  135. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_durable_selection.py +0 -0
  136. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_empty_callback_failure.py +0 -0
  137. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_errors.py +0 -0
  138. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_external_storage.py +0 -0
  139. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_external_task_input.py +0 -0
  140. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_external_task_result.py +0 -0
  141. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_failure_reporting.py +0 -0
  142. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_generator_lifecycle.py +0 -0
  143. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_golden_history_replay.py +0 -0
  144. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_history_bundle_pruned.py +0 -0
  145. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_history_bundle_schema2.py +0 -0
  146. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_history_bundle_verify.py +0 -0
  147. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_history_event_contract.py +0 -0
  148. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_invocable.py +0 -0
  149. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_local_activity_backoff.py +0 -0
  150. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_local_failure_reporting.py +0 -0
  151. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_message_streams.py +0 -0
  152. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_metric_routes.py +0 -0
  153. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_metrics.py +0 -0
  154. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_native_timer_redrive_cell.py +0 -0
  155. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_native_timer_redrive_clock.py +0 -0
  156. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_nexus_durable_wait.py +0 -0
  157. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_nexus_namespace.py +0 -0
  158. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_nexus_wire.py +0 -0
  159. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_order_processing_example.py +0 -0
  160. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_parallel_completion_order_replay.py +0 -0
  161. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_parallel_group_policy.py +0 -0
  162. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_parallel_saga_authoring.py +0 -0
  163. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_patch_history.py +0 -0
  164. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_pending_operation_replay.py +0 -0
  165. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_physical_command_key_readback.py +0 -0
  166. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_poll_transport.py +0 -0
  167. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_portal_source_split.py +0 -0
  168. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_prepared_local_activity_client.py +0 -0
  169. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_prepared_local_activity_groups.py +0 -0
  170. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_prepared_local_activity_policies.py +0 -0
  171. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_prepared_local_activity_worker.py +0 -0
  172. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_public_boundary_scanner.py +0 -0
  173. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_publish_workflow_isolation.py +0 -0
  174. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_published_activity_acceptance.py +0 -0
  175. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_published_pagination_evidence.py +0 -0
  176. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_pypi_project_surface.py +0 -0
  177. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_python_conformance.py +0 -0
  178. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_queries.py +0 -0
  179. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_query_task_authority.py +0 -0
  180. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_query_timeout_retry.py +0 -0
  181. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_quiesced_snapshot.py +0 -0
  182. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_readme_quickstart.py +0 -0
  183. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_redrive_call_ledger.py +0 -0
  184. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_redrive_replay.py +0 -0
  185. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_redrive_successor_evidence.py +0 -0
  186. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_registration_ambiguity.py +0 -0
  187. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_release_metadata.py +0 -0
  188. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_release_promotion.py +0 -0
  189. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_replay.py +0 -0
  190. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_replay_clock.py +0 -0
  191. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_replay_conformance.py +0 -0
  192. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_replay_verify.py +0 -0
  193. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_retry_cap_download.py +0 -0
  194. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_retry_cap_workflow.py +0 -0
  195. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_retry_policy.py +0 -0
  196. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_run_activities.py +0 -0
  197. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_run_cancellation_scope_replay.py +0 -0
  198. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_run_closed_settlement_replay.py +0 -0
  199. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_runtime_external_payload_transport.py +0 -0
  200. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_schedule_origin.py +0 -0
  201. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_schedules.py +0 -0
  202. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_scoped_run_cancellation_context.py +0 -0
  203. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_sdk_metrics_contract.py +0 -0
  204. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_search_attribute_replay_identity.py +0 -0
  205. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_serializer.py +0 -0
  206. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_signal_external_workflow.py +0 -0
  207. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_signal_with_start.py +0 -0
  208. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_signals.py +0 -0
  209. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_sleep.py +0 -0
  210. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_standalone_activity_client.py +0 -0
  211. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_static_credential_validation.py +0 -0
  212. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_sticky_execution.py +0 -0
  213. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_sticky_history_suffix.py +0 -0
  214. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_storage_admission.py +0 -0
  215. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_sync.py +0 -0
  216. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_sync_activities.py +0 -0
  217. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_synthetic_command_key_readback.py +0 -0
  218. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_telemetry.py +0 -0
  219. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_telemetry_carrier.py +0 -0
  220. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_testing_failures.py +0 -0
  221. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_testing_harness.py +0 -0
  222. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_testing_nexus.py +0 -0
  223. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_tls_trust.py +0 -0
  224. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_transport_diagnostics.py +0 -0
  225. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_typed_values.py +0 -0
  226. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_typed_workflow_values.py +0 -0
  227. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_update_outcome.py +0 -0
  228. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_update_signal_condition_replay.py +0 -0
  229. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_updates.py +0 -0
  230. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_wait_condition.py +0 -0
  231. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_worker_deregistration.py +0 -0
  232. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_worker_observation.py +0 -0
  233. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_worker_session.py +0 -0
  234. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_worker_startup_buffered.py +0 -0
  235. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_worker_startup_raw.py +0 -0
  236. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_worker_startup_read_budget.py +0 -0
  237. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_worker_startup_snapshot.py +0 -0
  238. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_worker_status.py +0 -0
  239. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_worker_telemetry_wire.py +0 -0
  240. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_workflow_entry_arguments.py +0 -0
  241. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_workflow_entrypoint_validation.py +0 -0
  242. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_workflow_handler_validation.py +0 -0
  243. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_workflow_identity.py +0 -0
  244. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_workflow_result_timeout.py +0 -0
  245. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_workflow_streams.py +0 -0
  246. {durable_workflow-2.20.0 → durable_workflow-2.21.1}/tests/test_workflow_updates_conformance.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: durable-workflow
3
- Version: 2.20.0
3
+ Version: 2.21.1
4
4
  Summary: Python client and worker SDK for Durable Workflow Cloud and self-hosted Server
5
5
  Author: Durable Workflow Contributors
6
6
  License-Expression: MIT
@@ -207,7 +207,8 @@ after cancellation. The disposal guarantees require SDK 2.12.2 or later.
207
207
 
208
208
  Both `await activity.context().heartbeat()` and synchronous
209
209
  `activity.context().heartbeat_sync()` stop at an explicit Server refusal.
210
- They raise `ActivityLeaseAuthorityLost` with its original `.reason` for an
210
+ They raise `ActivityWorkerLost` (formerly `ActivityLeaseAuthorityLost`, still
211
+ importable under that name) with its original `.reason` for an
211
212
  elapsed deadline, closed attempt or closed run. Cancellation continues to raise
212
213
  `ActivityCancelled`. The worker submits no result or failure for an attempt
213
214
  whose heartbeat refused continuation, even if application code catches that
@@ -160,7 +160,8 @@ after cancellation. The disposal guarantees require SDK 2.12.2 or later.
160
160
 
161
161
  Both `await activity.context().heartbeat()` and synchronous
162
162
  `activity.context().heartbeat_sync()` stop at an explicit Server refusal.
163
- They raise `ActivityLeaseAuthorityLost` with its original `.reason` for an
163
+ They raise `ActivityWorkerLost` (formerly `ActivityLeaseAuthorityLost`, still
164
+ importable under that name) with its original `.reason` for an
164
165
  elapsed deadline, closed attempt or closed run. Cancellation continues to raise
165
166
  `ActivityCancelled`. The worker submits no result or failure for an attempt
166
167
  whose heartbeat refused continuation, even if application code catches that
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "durable-workflow"
7
- version = "2.20.0"
7
+ version = "2.21.1"
8
8
  description = "Python client and worker SDK for Durable Workflow Cloud and self-hosted Server"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -79,8 +79,8 @@ durable-workflow-replay-conformance = "durable_workflow.replay_conformance:main"
79
79
  durable-workflow-workflow-updates-conformance = "durable_workflow.workflow_updates_conformance:main"
80
80
 
81
81
  [tool.durable-workflow]
82
- product-train = "2.20.0"
83
- registry-version = "2.20.0"
82
+ product-train = "2.21.1"
83
+ registry-version = "2.21.1"
84
84
  supported-server-versions = "2.8.0"
85
85
  supported-server-release-baselines = { "2" = "2.8.0", "3" = "3.0.0" }
86
86
  worker-protocol-version = "1.20"
@@ -3,7 +3,11 @@
3
3
  from __future__ import annotations
4
4
 
5
5
  import asyncio
6
+ import functools
7
+ import logging
8
+ import random
6
9
  import re
10
+ import threading
7
11
  import time
8
12
  from collections.abc import Awaitable, Callable, Mapping
9
13
  from contextvars import ContextVar
@@ -14,10 +18,114 @@ from urllib.parse import quote
14
18
 
15
19
  import httpx
16
20
 
17
- from .errors import ActivityLeaseAuthorityLost, ServerError
21
+ from .errors import WORKER_LOST_FAILURE_TYPE, ActivityWorkerLost, ServerError
18
22
 
19
23
  _T = TypeVar("_T")
20
24
  _UTC6 = re.compile(r"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{6}Z\Z")
25
+ log = logging.getLogger("durable_workflow.worker")
26
+
27
+ #: Reason of the :class:`ActivityWorkerLost` raised when renewal kept
28
+ #: failing until only the release reserve of the lease was left. The worker
29
+ #: then stops the execution and, once it has confirmed the stop inside the
30
+ #: lease, releases the claim through the Server as ``worker_lost``.
31
+ ACTIVITY_LEASE_RENEWAL_EXHAUSTED = "activity_lease_renewal_unavailable"
32
+ # Part of the lease kept back to stop the execution and release the claim: at
33
+ # most this many seconds, and at most a fifth of the granted lease. The first
34
+ # half is for confirming the stop, the second for the release request.
35
+ _REPORT_RESERVE_SECONDS = 10.0
36
+ _REPORT_RESERVE_FRACTION = 0.2
37
+ # Renewal retry backoff after a transient failure, the same in every SDK:
38
+ # delay = uniform(0, min(MAX, BASE * 2**n)) for the n-th retry (full jitter).
39
+ _RETRY_BASE_SECONDS = 0.25
40
+ _RETRY_MAX_SECONDS = 4.0
41
+ # How often a stop confirmation re-checks threads and callback processes.
42
+ _STOP_POLL_SECONDS = 0.02
43
+ # Upper bound of one renewal exchange (the client accepts at most five).
44
+ _RENEWAL_TIMEOUT_SECONDS = 5.0
45
+
46
+
47
+ def renewal_retry_delay(failures: int) -> float:
48
+ """Full-jitter backoff before the retry after ``failures`` consecutive failures."""
49
+ exponent = min(max(failures - 1, 0), 16)
50
+ return random.uniform(0.0, min(_RETRY_MAX_SECONDS, _RETRY_BASE_SECONDS * 2 ** exponent))
51
+
52
+
53
+ async def release_worker_lost(client: Any, *, task_id: str, activity_attempt_id: str, lease_owner: str,
54
+ cause: str, timeout: float) -> bool:
55
+ """Release a claim the worker cannot maintain, by the cross-SDK contract.
56
+
57
+ Call only after the execution is confirmed stopped (or never started):
58
+ the Server may hand the attempt to another worker as soon as it records
59
+ this retryable ``worker_lost`` failure.
60
+ """
61
+ try:
62
+ await asyncio.wait_for(client.fail_activity_task(
63
+ task_id=task_id, activity_attempt_id=activity_attempt_id, lease_owner=lease_owner,
64
+ message=f"activity worker released the claim: lease could not be renewed ({cause})",
65
+ failure_type=WORKER_LOST_FAILURE_TYPE, failure_class=ActivityWorkerLost.__name__,
66
+ non_retryable=False, details={"reason": WORKER_LOST_FAILURE_TYPE, "cause": cause},
67
+ ), timeout=timeout)
68
+ return True
69
+ except Exception as error:
70
+ if isinstance(error, ServerError) and error.reason() == "run_closed":
71
+ log.info("worker_lost release for activity task %s not recorded: its workflow run closed", task_id)
72
+ else:
73
+ log.warning("activity claim %s could not be released (%r); the Server settles it when the lease "
74
+ "expires", task_id, error)
75
+ return False
76
+
77
+
78
+ class _ThreadRun:
79
+ """Whether a claim's activity thread has stopped, without a start race.
80
+
81
+ A thread that has not started yet is fenced when asked, so it never runs
82
+ after a release; one that has started counts as stopped only once its
83
+ function has returned or raised.
84
+ """
85
+
86
+ def __init__(self, task_id: str) -> None:
87
+ self._task_id = task_id
88
+ self._lock = threading.Lock()
89
+ self._started = False
90
+ self._finished = False
91
+ self._fenced = False
92
+
93
+ def wrap(self, fn: Callable[..., _T]) -> Callable[..., _T]:
94
+ @functools.wraps(fn)
95
+ def guarded(*args: Any, **kwargs: Any) -> _T:
96
+ with self._lock:
97
+ if self._fenced:
98
+ raise ActivityWorkerLost(self._task_id, "activity_execution_abandoned")
99
+ self._started = True
100
+ try:
101
+ return fn(*args, **kwargs)
102
+ finally:
103
+ with self._lock:
104
+ self._finished = True
105
+ return guarded
106
+
107
+ def fence_or_finished(self) -> bool:
108
+ with self._lock:
109
+ if not self._started:
110
+ self._fenced = True
111
+ return True
112
+ return self._finished
113
+
114
+
115
+ def _execution_stopped(execution: Any) -> bool:
116
+ fence_or_finished = getattr(execution, "fence_or_finished", None)
117
+ if callable(fence_or_finished):
118
+ return bool(fence_or_finished())
119
+ done = getattr(execution, "done", None)
120
+ if callable(done):
121
+ return bool(done())
122
+ return getattr(execution, "stopped", False) is True
123
+
124
+
125
+ def _transient(error: BaseException) -> bool:
126
+ """A failed exchange that grants nothing but does not revoke the claim."""
127
+ return (isinstance(error, (httpx.TransportError, asyncio.TimeoutError))
128
+ or isinstance(error, ServerError) and (error.status >= 500 or error.status == 429))
21
129
 
22
130
 
23
131
  def _timestamp(value: Any) -> datetime:
@@ -64,10 +172,19 @@ class ActivityLeaseAuthority:
64
172
  heartbeat_deadline: datetime | None
65
173
  last_renewal: tuple[datetime, datetime, float] | None = None
66
174
  lost_reason: str | None = field(default=None, init=False)
175
+ # Length of the latest confirmed grant, and consecutive transient renewal
176
+ # failures since it. Neither changes recorded history.
177
+ lease_seconds: float = field(default=0.0, init=False)
178
+ renewal_failures: int = field(default=0, init=False)
179
+ # Physical executions (activity threads, callback processes) started for
180
+ # this claim. A release waits until every one has actually stopped.
181
+ executions: list[Any] = field(default_factory=list, init=False)
182
+ execution_started: bool = field(default=False, init=False)
67
183
 
68
184
  @classmethod
69
185
  async def confirm_delivery(cls, client: Any, namespace: str, task: Mapping[str, Any], *, owner: str,
70
- task_queue: str, server_time: Any) -> ActivityLeaseAuthority:
186
+ task_queue: str, server_time: Any,
187
+ poll_started: float | None = None) -> ActivityLeaseAuthority:
71
188
  # A long poll may wait before a task or its lease exists. Establish the
72
189
  # first execution budget with a separate, original-claim confirmation;
73
190
  # its entire round trip is charged and it cannot revive an expired lease.
@@ -75,16 +192,27 @@ class ActivityLeaseAuthority:
75
192
  server_time=server_time, request_started=time.monotonic())
76
193
  started = time.monotonic()
77
194
  try:
195
+ budget = provisional.renewal_budget()
196
+ if budget <= 0:
197
+ raise asyncio.TimeoutError("no time left to confirm the claim outside the report reserve")
78
198
  reply = await client.renew_activity_task_lease(
79
199
  task_id=provisional.task_id, activity_attempt_id=provisional.identity["activity_attempt_id"],
80
- lease_owner=owner, timeout=min(5.0, provisional.remaining()),
200
+ lease_owner=owner, timeout=budget,
81
201
  )
82
202
  provisional.acknowledge(reply, started)
83
- except ActivityLeaseAuthorityLost:
203
+ except ActivityWorkerLost:
84
204
  raise
85
205
  except Exception as error:
206
+ if _transient(error):
207
+ # A slow or flaky link is not a lost claim (sdk-php#445). Keep
208
+ # the claim under the poll's grant and let maintenance retry
209
+ # the confirmation with backoff.
210
+ return await cls._unconfirmed_delivery(
211
+ client, namespace, task, owner=owner, task_queue=task_queue, server_time=server_time,
212
+ poll_started=started if poll_started is None else poll_started, error=error,
213
+ )
86
214
  reason = error.reason() if isinstance(error, ServerError) else None
87
- raise ActivityLeaseAuthorityLost(
215
+ raise ActivityWorkerLost(
88
216
  provisional.task_id, reason or "activity_initial_lease_unavailable",
89
217
  ) from error
90
218
  observed = dict(task)
@@ -96,6 +224,33 @@ class ActivityLeaseAuthority:
96
224
  return cls.delivery(client, namespace, observed, owner=owner, task_queue=task_queue,
97
225
  server_time=reply["server_time"], request_started=started)
98
226
 
227
+ @classmethod
228
+ async def _unconfirmed_delivery(cls, client: Any, namespace: str, task: Mapping[str, Any], *, owner: str,
229
+ task_queue: str, server_time: Any, poll_started: float,
230
+ error: BaseException) -> ActivityLeaseAuthority:
231
+ # The Server stamps the lease after it receives the poll, so charging
232
+ # the grant from the poll's start is the conservative bound.
233
+ try:
234
+ grant = cls.delivery(client, namespace, task, owner=owner, task_queue=task_queue,
235
+ server_time=server_time, request_started=poll_started)
236
+ except ActivityWorkerLost:
237
+ grant = None
238
+ if grant is None or grant.lease_until - time.monotonic() <= grant.report_reserve():
239
+ # Nothing has run, so releasing cannot cause a second concurrent
240
+ # execution; a stale release is refused by the Server.
241
+ task_id = str(task.get("task_id") or "")
242
+ log.warning("activity task %s initial lease confirmation failed (%r) and the conservative grant is "
243
+ "spent; releasing the unstarted claim", task_id, error)
244
+ await release_worker_lost(
245
+ client, task_id=task_id, activity_attempt_id=str(task.get("activity_attempt_id") or ""),
246
+ lease_owner=owner, cause=ACTIVITY_LEASE_RENEWAL_EXHAUSTED, timeout=_RENEWAL_TIMEOUT_SECONDS,
247
+ )
248
+ raise ActivityWorkerLost(task_id, ACTIVITY_LEASE_RENEWAL_EXHAUSTED) from error
249
+ grant.renewal_failures = 1
250
+ log.warning("activity task %s initial lease confirmation failed (%r); continuing under the claimed "
251
+ "lease and retrying", grant.task_id, error)
252
+ return grant
253
+
99
254
  @classmethod
100
255
  def delivery(cls, client: Any, namespace: str, task: Mapping[str, Any], *, owner: str,
101
256
  task_queue: str, server_time: Any, request_started: float) -> ActivityLeaseAuthority:
@@ -134,7 +289,8 @@ class ActivityLeaseAuthority:
134
289
  heartbeat,
135
290
  )
136
291
  except (KeyError, TypeError, ValueError, OverflowError) as error:
137
- raise ActivityLeaseAuthorityLost(task_id, "invalid_activity_claim") from error
292
+ raise ActivityWorkerLost(task_id, "invalid_activity_claim") from error
293
+ result.lease_seconds = duration
138
294
  result.remaining()
139
295
  return result
140
296
 
@@ -194,19 +350,52 @@ class ActivityLeaseAuthority:
194
350
  self.lease_expiry = max(self.lease_expiry, expiry)
195
351
  except (TypeError, ValueError, OverflowError) as error:
196
352
  self.lost_reason = "invalid_activity_heartbeat"
197
- raise ActivityLeaseAuthorityLost(self.task_id, self.lost_reason) from error
353
+ raise ActivityWorkerLost(self.task_id, self.lost_reason) from error
198
354
 
199
355
  def remaining(self) -> float:
200
356
  if self.lost_reason is not None:
201
- raise ActivityLeaseAuthorityLost(self.task_id, self.lost_reason)
357
+ raise ActivityWorkerLost(self.task_id, self.lost_reason)
202
358
  bounds = [self.lease_until, *(value for value in (self.business_until, self.heartbeat_until)
203
359
  if value is not None)]
204
360
  remaining = min(bounds) - time.monotonic()
205
361
  if remaining <= 0:
206
362
  self.lost_reason = "activity_execution_budget_expired"
207
- raise ActivityLeaseAuthorityLost(self.task_id, self.lost_reason)
363
+ raise ActivityWorkerLost(self.task_id, self.lost_reason)
208
364
  return remaining
209
365
 
366
+ def report_reserve(self) -> float:
367
+ """Lease time kept back to fail the attempt if renewal keeps failing."""
368
+ return min(_REPORT_RESERVE_SECONDS, self.lease_seconds * _REPORT_RESERVE_FRACTION)
369
+
370
+ def renewal_budget(self) -> float:
371
+ """Bound one renewal so a timeout still leaves the report reserve."""
372
+ return min(_RENEWAL_TIMEOUT_SECONDS, self.remaining(),
373
+ self.lease_until - time.monotonic() - self.report_reserve())
374
+
375
+ def track(self, execution: Any) -> None:
376
+ """Register an execution (callback process, future) that runs this claim."""
377
+ self.executions.append(execution)
378
+
379
+ def guard_thread(self, fn: Callable[..., _T]) -> Callable[..., _T]:
380
+ """Wrap a synchronous activity so its thread is tracked for this claim."""
381
+ run = _ThreadRun(self.task_id)
382
+ self.track(run)
383
+ return run.wrap(fn)
384
+
385
+ async def confirm_stopped(self, deadline: float) -> bool:
386
+ """Wait until every tracked execution has stopped, or ``deadline`` passes."""
387
+ while not all(_execution_stopped(execution) for execution in self.executions):
388
+ left = deadline - time.monotonic()
389
+ if left <= 0:
390
+ return False
391
+ await asyncio.sleep(min(_STOP_POLL_SECONDS, left))
392
+ return time.monotonic() < deadline
393
+
394
+ def renewal_exhausted(self) -> bool:
395
+ """Renewal has failed and only the report reserve of the lease is left."""
396
+ return (self.renewal_failures > 0
397
+ and self.lease_until - time.monotonic() <= self.report_reserve())
398
+
210
399
  def acknowledge(self, reply: Any, request_started: float) -> None:
211
400
  self.remaining()
212
401
  received = time.monotonic()
@@ -235,11 +424,12 @@ class ActivityLeaseAuthority:
235
424
  return
236
425
  raise ValueError("replayed activity renewal")
237
426
  self.lease_until = max(self.lease_until, request_started + duration)
427
+ self.lease_seconds = duration
238
428
  self._observe_progress(reply, server, request_started, received)
239
429
  self.server_time, self.lease_expiry, self.last_renewal = server, expiry, confirmation
240
430
  except (TypeError, ValueError, OverflowError) as error:
241
431
  self.lost_reason = "invalid_activity_renewal"
242
- raise ActivityLeaseAuthorityLost(self.task_id, self.lost_reason) from error
432
+ raise ActivityWorkerLost(self.task_id, self.lost_reason) from error
243
433
 
244
434
  def _observe_progress(self, reply: Mapping[str, Any], server: datetime, started: float, received: float) -> None:
245
435
  if self.heartbeat_until is None or self.heartbeat_timeout is None:
@@ -260,38 +450,58 @@ class ActivityLeaseAuthority:
260
450
  async def renew(self) -> bool:
261
451
  started = time.monotonic()
262
452
  try:
453
+ budget = self.renewal_budget()
454
+ if budget <= 0:
455
+ # No time for a renewal that would still leave the reserve.
456
+ self.renewal_failures += 1
457
+ return False
263
458
  reply = await asyncio.wait_for(self.client.renew_activity_task_lease(
264
459
  task_id=self.task_id, activity_attempt_id=self.identity["activity_attempt_id"],
265
- lease_owner=self.identity["lease_owner"], timeout=min(5.0, self.remaining()),
266
- ), timeout=min(5.0, self.remaining()))
460
+ lease_owner=self.identity["lease_owner"], timeout=budget,
461
+ ), timeout=budget)
267
462
  self.acknowledge(reply, started)
463
+ self.renewal_failures = 0
268
464
  return True
269
- except ActivityLeaseAuthorityLost:
465
+ except ActivityWorkerLost:
270
466
  raise
271
467
  except Exception as error:
272
- if (isinstance(error, (httpx.TransportError, asyncio.TimeoutError))
273
- or isinstance(error, ServerError) and (error.status >= 500 or error.status == 429)):
468
+ if _transient(error):
274
469
  # A failed exchange grants nothing. The existing lease may
275
470
  # still authorize work until its original local bound.
471
+ self.renewal_failures += 1
276
472
  self.remaining()
277
473
  return False
278
474
  self.lost_reason = "activity_renewal_unavailable"
279
- raise ActivityLeaseAuthorityLost(self.task_id, self.lost_reason) from error
475
+ raise ActivityWorkerLost(self.task_id, self.lost_reason) from error
280
476
 
281
477
  async def _maintain(self, stopped: asyncio.Event) -> None:
282
- confirmed = True
283
478
  while not stopped.is_set():
284
- delay = min(30.0 if confirmed else 1.0, max(0.0, self.lease_until - time.monotonic()) / 3)
479
+ lease_left = max(0.0, self.lease_until - time.monotonic())
480
+ if self.renewal_failures:
481
+ # Back off with full jitter on a struggling link, but keep
482
+ # retrying inside the grant, ahead of the release reserve.
483
+ delay = min(renewal_retry_delay(self.renewal_failures),
484
+ max(0.0, lease_left - self.report_reserve()) / 3)
485
+ else:
486
+ delay = min(30.0, lease_left / 3)
285
487
  if self.heartbeat_timeout is not None:
286
488
  delay = min(delay, self.heartbeat_timeout / 3)
287
489
  await asyncio.sleep(min(delay, self.remaining()))
288
490
  if stopped.is_set():
289
491
  return
290
- confirmed = await self.renew()
492
+ if self.renewal_exhausted():
493
+ self.lost_reason = ACTIVITY_LEASE_RENEWAL_EXHAUSTED
494
+ return
495
+ await self.renew()
291
496
 
292
497
  async def run(self, operation: Callable[[], Awaitable[_T]]) -> _T:
293
498
  self.remaining()
499
+ if self.renewal_exhausted():
500
+ # Never start work that could not be confirmed stopped in time.
501
+ self.lost_reason = ACTIVITY_LEASE_RENEWAL_EXHAUSTED
502
+ raise ActivityWorkerLost(self.task_id, self.lost_reason)
294
503
  stopped = asyncio.Event()
504
+ self.execution_started = True
295
505
  execution = asyncio.ensure_future(operation())
296
506
  maintenance = asyncio.create_task(self._maintain(stopped))
297
507
  try:
@@ -300,7 +510,7 @@ class ActivityLeaseAuthority:
300
510
  return_when=asyncio.FIRST_COMPLETED)
301
511
  if maintenance in done:
302
512
  await maintenance
303
- raise ActivityLeaseAuthorityLost(self.task_id, "activity_renewal_stopped")
513
+ raise ActivityWorkerLost(self.task_id, self.lost_reason or "activity_renewal_stopped")
304
514
  if execution in done:
305
515
  result = await execution
306
516
  self.remaining()
@@ -0,0 +1,104 @@
1
+ """Worker answers without repeated ``server_capabilities`` (server#1262).
2
+
3
+ A worker request sends the digest of the capabilities this client holds, or
4
+ ``none``. A Server that supports the digest answers with each copy of its
5
+ current capabilities either tagged with a ``digest`` member, which is kept for
6
+ later requests, or replaced by the digest string, which is restored here before
7
+ any caller sees the answer. Older Servers ignore the header and answer in full,
8
+ so callers always observe complete capabilities.
9
+
10
+ The Server only replaces copies with the digest that request sent, so an answer
11
+ is resolved against the pair captured when its request was sent, not the pair
12
+ held when it arrives. Overlapping requests across a change of capabilities (a
13
+ rolling deploy) each restore their own object. Contract:
14
+ ``docs/contracts/server-capabilities-digest.md`` in the Server repository.
15
+ """
16
+
17
+ from __future__ import annotations
18
+
19
+ import copy
20
+ from typing import Any
21
+
22
+ from .errors import ServerCapabilitiesDigestError
23
+
24
+ HEADER = "X-Durable-Workflow-Server-Capabilities-Digest"
25
+ _KEY = "server_capabilities"
26
+ _PREFIX = "sha256:"
27
+ # The Server elides copies at the top level and up to two objects deep.
28
+ _MAX_DEPTH = 3
29
+
30
+ Captured = tuple[str | None, dict[str, Any] | None]
31
+
32
+
33
+ class ServerCapabilitiesDigest:
34
+ """The newest (digest, capabilities) pair this client has learned."""
35
+
36
+ def __init__(self) -> None:
37
+ self._digest: str | None = None
38
+ self._capabilities: dict[str, Any] | None = None
39
+
40
+ def capture(self) -> Captured:
41
+ """The pair a request is sent with; pass it to :meth:`restore` for its answer."""
42
+ return self._digest, self._capabilities
43
+
44
+ @staticmethod
45
+ def header(captured: Captured) -> str:
46
+ return captured[0] if captured[0] is not None and captured[1] is not None else "none"
47
+
48
+ def forget(self) -> None:
49
+ """Drop the held pair, so the next request sends ``none`` and gets full capabilities."""
50
+ self._digest = None
51
+ self._capabilities = None
52
+
53
+ def restore(self, answer: Any, captured: Captured, *, drop_unknown: bool = False,
54
+ substitute: dict[str, Any] | None = None) -> bool:
55
+ """Strip and learn tagged copies, then restore elided ones, in place.
56
+
57
+ An elided copy naming a digest neither captured for the request nor
58
+ tagged in this answer raises :class:`ServerCapabilitiesDigestError`.
59
+ With ``substitute`` it is replaced by a copy of that object; with
60
+ ``drop_unknown`` it is removed. Either way ``True`` is returned.
61
+ """
62
+ if not isinstance(answer, dict):
63
+ return False
64
+ learned: dict[str, dict[str, Any]] = {}
65
+ self._learn(answer, learned, 1)
66
+ return self._resolve(answer, captured, learned, 1, drop_unknown, substitute)
67
+
68
+ def _learn(self, answer: dict[str, Any], learned: dict[str, dict[str, Any]], depth: int) -> None:
69
+ for key, value in answer.items():
70
+ if key == _KEY:
71
+ if isinstance(value, dict) and isinstance(value.get("digest"), str) \
72
+ and value["digest"].startswith(_PREFIX):
73
+ digest = value.pop("digest")
74
+ learned[digest] = value
75
+ # Later requests send the newest digest this client has seen.
76
+ # Callers own the answer, so the held pair is a private copy.
77
+ self._digest, self._capabilities = digest, copy.deepcopy(value)
78
+ elif isinstance(value, dict) and depth < _MAX_DEPTH:
79
+ self._learn(value, learned, depth + 1)
80
+
81
+ def _resolve(self, answer: dict[str, Any], captured: Captured, learned: dict[str, dict[str, Any]],
82
+ depth: int, drop_unknown: bool, substitute: dict[str, Any] | None) -> bool:
83
+ dropped = False
84
+ for key, value in list(answer.items()):
85
+ if key == _KEY:
86
+ if isinstance(value, str) and value.startswith(_PREFIX):
87
+ if value == captured[0] and captured[1] is not None:
88
+ answer[key] = copy.deepcopy(captured[1])
89
+ elif value in learned:
90
+ answer[key] = copy.deepcopy(learned[value])
91
+ elif substitute is not None:
92
+ answer[key] = copy.deepcopy(substitute)
93
+ dropped = True
94
+ elif drop_unknown:
95
+ del answer[key]
96
+ dropped = True
97
+ else:
98
+ raise ServerCapabilitiesDigestError(
99
+ "the Server elided server_capabilities this worker does not hold "
100
+ f"({value}; sent {self.header(captured)})"
101
+ )
102
+ elif isinstance(value, dict) and depth < _MAX_DEPTH:
103
+ dropped = self._resolve(value, captured, learned, depth + 1, drop_unknown, substitute) or dropped
104
+ return dropped
@@ -0,0 +1,74 @@
1
+ """Bound the decoded size of every HTTP response body.
2
+
3
+ httpx decodes ``Content-Encoding: gzip`` transparently, so a small compressed
4
+ answer could expand without limit in memory (a 1.5 MB gzip body can inflate to
5
+ gigabytes). Each response stream is wrapped before httpx reads it: the wrapper
6
+ counts the bytes the body decodes to, inflating at most 1 MiB at a time, and
7
+ raises :class:`~durable_workflow.errors.ResponseBodyTooLarge` before httpx
8
+ decodes a chunk that would cross the limit.
9
+ """
10
+
11
+ from __future__ import annotations
12
+
13
+ import zlib
14
+ from collections.abc import AsyncIterator, Awaitable, Callable
15
+
16
+ import httpx
17
+
18
+ from .errors import ResponseBodyTooLarge
19
+
20
+ #: Default bound on a decoded response body: 128 MiB.
21
+ DEFAULT_MAX_RESPONSE_BODY_BYTES = 128 * 1024 * 1024
22
+ #: Encodings this client asks for; httpx is not offered others.
23
+ ACCEPT_ENCODING = "gzip"
24
+ _INFLATE_STEP = 1 << 20
25
+
26
+
27
+ class _BoundedBody(httpx.AsyncByteStream):
28
+ def __init__(self, inner: httpx.AsyncByteStream, *, gzip: bool, limit: int, url: str) -> None:
29
+ self._inner = inner
30
+ self._gzip = gzip
31
+ self._limit = limit
32
+ self._url = url
33
+
34
+ async def __aiter__(self) -> AsyncIterator[bytes]:
35
+ inflater = zlib.decompressobj(16 + zlib.MAX_WBITS) if self._gzip else None
36
+ decoded = 0
37
+ async for chunk in self._inner:
38
+ if inflater is None:
39
+ decoded += len(chunk)
40
+ else:
41
+ pending = chunk
42
+ while pending and not inflater.eof:
43
+ try:
44
+ decoded += len(inflater.decompress(pending, _INFLATE_STEP))
45
+ except zlib.error:
46
+ # Not ours to judge: httpx reports the invalid encoding.
47
+ inflater = None
48
+ break
49
+ if decoded > self._limit:
50
+ break
51
+ pending = inflater.unconsumed_tail
52
+ if decoded > self._limit:
53
+ raise ResponseBodyTooLarge(self._limit, self._url)
54
+ yield chunk
55
+
56
+ async def aclose(self) -> None:
57
+ await self._inner.aclose()
58
+
59
+
60
+ def response_body_limit(limit: int) -> Callable[[httpx.Response], Awaitable[None]]:
61
+ """An httpx response hook that bounds the decoded body at ``limit`` bytes."""
62
+
63
+ async def bound(response: httpx.Response) -> None:
64
+ encoding = response.headers.get("content-encoding", "").strip().lower()
65
+ if encoding not in ("", "identity", "gzip"):
66
+ raise httpx.DecodingError(
67
+ f"unrequested response content-encoding {encoding!r}", request=response.request,
68
+ )
69
+ if isinstance(response.stream, httpx.AsyncByteStream):
70
+ response.stream = _BoundedBody(
71
+ response.stream, gzip=encoding == "gzip", limit=limit, url=str(response.request.url.path),
72
+ )
73
+
74
+ return bound
@@ -10,7 +10,7 @@ from typing import TYPE_CHECKING, Any
10
10
 
11
11
  from ._activity_checkpoint import ActivityHeartbeatCheckpoint, _HeartbeatResume, claim_resume
12
12
  from ._activity_lease import current_activity_authority
13
- from .errors import ActivityCancelled, ActivityLeaseAuthorityLost
13
+ from .errors import ActivityCancelled, ActivityWorkerLost
14
14
 
15
15
  if TYPE_CHECKING:
16
16
  from .client import Client
@@ -190,7 +190,7 @@ class ActivityContext:
190
190
  owning workflow has requested cancellation, so the activity can exit
191
191
  cleanly at its next natural break point.
192
192
 
193
- Raises :class:`~durable_workflow.errors.ActivityLeaseAuthorityLost`
193
+ Raises :class:`~durable_workflow.errors.ActivityWorkerLost`
194
194
  with the original Server reason when the attempt cannot continue,
195
195
  including an elapsed deadline, closed attempt or closed run.
196
196
  """
@@ -225,7 +225,7 @@ class ActivityContext:
225
225
  and authority.identity["attempt_number"] == self._info.attempt_number
226
226
  and authority.identity["lease_owner"] == self._info.worker_id):
227
227
  authority.lost_reason = authority.lost_reason or self._cannot_continue_reason
228
- raise ActivityLeaseAuthorityLost(self._info.task_id, self._cannot_continue_reason)
228
+ raise ActivityWorkerLost(self._info.task_id, self._cannot_continue_reason)
229
229
 
230
230
 
231
231
  def context() -> ActivityContext: