feat(taskbroker): propagate TaskError from worker and log failure context on broker#607
feat(taskbroker): propagate TaskError from worker and log failure context on broker#607s-starostin wants to merge 2 commits intogetsentry:mainfrom
Conversation
| try: | ||
| with timeout_alarm(inflight.activation.processing_deadline_duration, handle_alarm): | ||
| _execute_activation(task_func, inflight.activation, app.context_hooks) | ||
| _execute_activation(task_func, inflight.activation, app.context_hooks, app.error_hook) |
There was a problem hiding this comment.
Bug: The function _execute_activation is called with an extra argument, app.error_hook, which will cause a TypeError at runtime.
Severity: CRITICAL
Suggested Fix
Remove the fourth argument, app.error_hook, from the call to _execute_activation on line 242. The error hook is already correctly invoked in the surrounding exception handlers.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: clients/python/src/taskbroker_client/worker/workerchild.py#L242
Potential issue: The function `_execute_activation` is called on line 242 with four
positional arguments: `task_func`, `inflight.activation`, `app.context_hooks`, and
`app.error_hook`. However, the function's definition only accepts a maximum of three
arguments. The fourth argument, `app.error_hook`, has no corresponding parameter. Since
the function does not use `*args` or `**kwargs` to accept arbitrary arguments, this
mismatch will cause a `TypeError` every time a task is processed, effectively preventing
any task execution.
Did we get this right? 👍 / 👎 to inform future reviews.
There was a problem hiding this comment.
Good catch, thanks - this is a valid bug.
I had a mismatch between the _execute_activation(...) call site and the function signature in workerchild.py. I've just pushed the fix.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit ca68733. Configure here.
ca68733 to
be25453
Compare
be25453 to
6fafc5b
Compare
| try: | ||
| with timeout_alarm(inflight.activation.processing_deadline_duration, handle_alarm): | ||
| _execute_activation(task_func, inflight.activation, app.context_hooks) | ||
| _execute_activation(task_func, inflight.activation, app.context_hooks, app.error_hook) |
| _execute_activation(task_func, inflight.activation, app.context_hooks, app.error_hook) | ||
| next_state = TASK_ACTIVATION_STATUS_COMPLETE | ||
| except ProcessingDeadlineExceeded as err: | ||
| if app.error_hook is not None: |
There was a problem hiding this comment.
Why does this happen first? Can we make this happen after all the other logging, so we can sure that a bug in a hook doesn't cause our reporting to break?
There was a problem hiding this comment.
Agreed.
I changed this so the existing reporting path runs first, and the hook is now invoked later via _get_task_error_from_hook(...) as best-effort only. A hook bug should no longer interfere with retry / logging / Sentry reporting; it only affects the optional TaskError payload.

Summary
Propagate task execution exception context from the Python worker client to taskbroker and emit structured broker-side failure logs.
This PR does two things:
error_hooksupport and propagatesTaskErrorinSetTaskStatusRequestTaskErroris presentDependency
Depends on
Downstream PR
Consumed by:
Changes
Python client
error_hooktoTaskbrokerApperror_hook.on_exception(task_meta, exc)in the worker exception pathTaskError | NonetoProcessingResulterrorinSetTaskStatusRequestBroker
request.errorinset_task_statusFailurealwaysRetryonly when an error envelope is presenterroris absentWhy
This lets taskbroker logs reflect what the worker actually observed when a task failed, instead of forcing operators to dig only through worker logs.
Logging behavior
Expected broker log shape:
task reported failure task_id=... taskname=... namespace=... status=Failure attempts=... exception_type="..." exception_message="..."Compatibility
errorstill workTests
Failurewitherrorlogs structured contextRetrywitherrorlogs structured contextRetrywithouterrordoes not emit failure logCompletedoes not emit failure logerrorstill worksFollow-up
getsentry/sentrywill consume the newerror_hooksurface and provide the Sentry-specific hook implementation.