Skip to content

feat: implement context propagation - #153

Open
timl3136 wants to merge 1 commit into
cadence-workflow:mainfrom
timl3136:context-propagation
Open

feat: implement context propagation#153
timl3136 wants to merge 1 commit into
cadence-workflow:mainfrom
timl3136:context-propagation

Conversation

@timl3136

Copy link
Copy Markdown
Member

What changed?

Why?

How did you test it?

Potential risks

Release notes

Documentation Changes

@timl3136
timl3136 force-pushed the context-propagation branch from 38c6f62 to 3f0ce78 Compare July 13, 2026 21:00
Comment on lines +111 to +117
try:
yield
finally:
try:
stack.close()
except Exception as exc:
raise ContextPropagationError("Context propagation cleanup failed") from exc

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Edge Case: Cleanup error in propagation scope masks in-flight exception

In context_propagation_scope, the finally block re-raises a ContextPropagationError from stack.close(). When the wrapped workflow/activity body raises a business exception (or ContinueAsNewError) and a propagator's extract context-manager exit also fails during unwind, the ContextPropagationError replaces the original exception as the propagated error (the original is only preserved via __context__). This can hide the true cause of a workflow/activity failure and make debugging harder. Consider suppressing or logging the cleanup error when an exception is already in flight, so the original error still surfaces.

Was this helpful? React with 👍 / 👎

@codecov

codecov Bot commented Jul 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.68293% with 12 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cadence/_internal/context_propagation.py 86.95% 6 Missing and 3 partials ⚠️
cadence/testing/_workflow_environment.py 94.11% 1 Missing and 1 partial ⚠️
cadence/worker/_types.py 66.66% 1 Missing ⚠️
Files with missing lines Coverage Δ
cadence/_internal/activity/_activity_executor.py 94.78% <100.00%> (+0.13%) ⬆️
cadence/_internal/activity/_context.py 92.98% <100.00%> (+0.32%) ⬆️
cadence/_internal/workflow/context.py 92.48% <100.00%> (+0.23%) ⬆️
.../_internal/workflow/statemachine/nondeterminism.py 92.57% <100.00%> (+0.35%) ⬆️
cadence/_internal/workflow/workflow_engine.py 91.21% <100.00%> (+0.37%) ⬆️
cadence/client.py 88.07% <100.00%> (+0.69%) ⬆️
cadence/context.py 100.00% <100.00%> (ø)
cadence/error.py 95.04% <100.00%> (+0.04%) ⬆️
cadence/worker/_activity.py 100.00% <ø> (ø)
cadence/worker/_decision_task_handler.py 88.63% <100.00%> (+0.08%) ⬆️
... and 4 more
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Signed-off-by: Tim Li <ltim@uber.com>
@timl3136
timl3136 force-pushed the context-propagation branch from 3f0ce78 to 532ad27 Compare July 14, 2026 21:46
@gitar-bot

gitar-bot Bot commented Jul 14, 2026

Copy link
Copy Markdown
Code Review 👍 Approved with suggestions 0 resolved / 1 findings

Implements comprehensive context propagation across clients, workers, and workflows using a new ContextPropagator protocol. Refactor the context_propagation_scope error handling to prevent the finally block from masking in-flight exceptions.

💡 Edge Case: Cleanup error in propagation scope masks in-flight exception

📄 cadence/_internal/context_propagation.py:111-117

In context_propagation_scope, the finally block re-raises a ContextPropagationError from stack.close(). When the wrapped workflow/activity body raises a business exception (or ContinueAsNewError) and a propagator's extract context-manager exit also fails during unwind, the ContextPropagationError replaces the original exception as the propagated error (the original is only preserved via __context__). This can hide the true cause of a workflow/activity failure and make debugging harder. Consider suppressing or logging the cleanup error when an exception is already in flight, so the original error still surfaces.

🤖 Prompt for agents
Code Review: Implements comprehensive context propagation across clients, workers, and workflows using a new `ContextPropagator` protocol. Refactor the `context_propagation_scope` error handling to prevent the `finally` block from masking in-flight exceptions.

1. 💡 Edge Case: Cleanup error in propagation scope masks in-flight exception
   Files: cadence/_internal/context_propagation.py:111-117

   In `context_propagation_scope`, the `finally` block re-raises a `ContextPropagationError` from `stack.close()`. When the wrapped workflow/activity body raises a business exception (or `ContinueAsNewError`) and a propagator's `extract` context-manager exit also fails during unwind, the `ContextPropagationError` replaces the original exception as the propagated error (the original is only preserved via `__context__`). This can hide the true cause of a workflow/activity failure and make debugging harder. Consider suppressing or logging the cleanup error when an exception is already in flight, so the original error still surfaces.

Options

Auto-apply is off → Gitar will not commit updates to this branch.
Display: compact → Showing less information.

Comment with these commands to change the behavior for this request:

Auto-apply Compact
gitar auto-apply:on         
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

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.

1 participant