-
Notifications
You must be signed in to change notification settings - Fork 338
Description
What happened?
Unless I have misunderstood the intent, there maybe an unintended short-circuit evaluation in the conditional assignment of self.context_id
a2a-python/src/a2a/server/tasks/task_manager.py
Lines 110 to 111 in 4050b81
| if not self.context_id and self.context_id != event.contextId: | |
| self.context_id = event.contextId |
-
When
self.context_idis falsy (None, empty string, etc.), then thenotclause forself.context_idevaluates toTrue- Due to short-circuit evaluation care of
and, Python never evaluates the second part:self.context_id != event.contextId - The condition becomes ~~
Trueand =True. ~~ - The code sets
self.context_id = event.contextId(which is correct behavior), ok so far.
- Due to short-circuit evaluation care of
-
When
self.context_idhas a value:- the not in
self.context_idevaluates toFalse - Due to short-circuit evaluation, the entire condition becomes
False - So context ID validation
self.context_id != event.contextIdnever runs
- the not in
So the current code will never detect mismatched context IDs because the validation check part is unreachable when self.context_id already has a value. Like I say though I might be wrong and forgive wasting time if so.
I think something like this should do the job:
if not self.task_id:
self.task_id = task_id_from_event
- if not self.context_id and self.context_id != event.contextId:
+ if self.context_id and self.context_id != event.contextId:
+ raise ServerError(
+ error=InvalidParamsError(
+ message=f"Context in event doesn't match TaskManager: {self.context_id} : {event.contextId}"
+ )
+ )
+ if not self.context_id:
self.context_id = event.contextId
Relevant log output
Code of Conduct
- I agree to follow this project's Code of Conduct
Metadata
Metadata
Assignees
Labels
No labels