Repository navigation
Commit c25022f
authored
fix(server): reject a message whose contextId disagrees with its task (a2aproject#1270)
## What
Spec
[3.4.3](https://a2a-protocol.org/latest/specification/#343-multi-turn-conversation-patterns):
"Agents **MUST** reject messages containing mismatching `contextId` and
`taskId` (i.e., the provided `contextId` is different from that of the
referenced `Task`)."
A follow-up carrying a real `taskId` with someone else's `contextId` was
accepted with HTTP 200, and the client's `contextId` was then written
into the task's history while the `Task` kept its own - two disagreeing
context ids inside one task.
## This guard already existed
`RequestContext` has carried it all along
(`agent_execution/context.py:77-78`). It only fires when a non-`None`
`task` reaches `build()`, and v2 passes `task=None` on purpose:
```python
# We will get the task when we have to process the request to avoid concurrent read/write issues.
task=None,
```
So the check went dead when V2 became the default. The legacy handler
passes the task and still rejects.
Rather than undo that deliberate `task=None`, the comparison goes where
v2 already fetches the task to prove it exists, one line after the
`TaskNotFoundError` it raises there. No extra read, and the task is not
retained.
## Scoped to requests that name a task
The check only runs under `if original_task_id:`. A `contextId` with no
`taskId` is a new task in an existing context, which stays legal -
`test_scenario_context_id_visibility` depends on it, and there is a test
here pinning it.
## A test that passed for the wrong reason
Worth flagging for review. `TaskManager` already rejects this mismatch
*once the agent emits an event*, with `Context in event doesn't match
TaskManager wrong-context : real-context`. That message happens to
contain both context ids, so the obvious assertion -
`pytest.raises(InvalidParamsError)` plus both ids in the message -
passes with or without this change. It did, and mutation testing is what
caught it.
The test now asserts the executor was never awaited. That is the actual
behavioural difference: the request is refused before any agent work
starts, instead of after the agent has already been handed a request
whose ids contradict each other.
## Result
Clears `CORE-MULTI-006` (`must`) on all three bindings.1 parent 8037b24 commit c25022f
2 files changed
Lines changed: 105 additions & 0 deletions
File tree
- src/a2a/server/request_handlers
- tests/server/request_handlers
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
237 | 237 | | |
238 | 238 | | |
239 | 239 | | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
240 | 249 | | |
241 | 250 | | |
242 | 251 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1130 | 1130 | | |
1131 | 1131 | | |
1132 | 1132 | | |
| 1133 | + | |
| 1134 | + | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
| 1164 | + | |
| 1165 | + | |
| 1166 | + | |
| 1167 | + | |
| 1168 | + | |
| 1169 | + | |
| 1170 | + | |
| 1171 | + | |
| 1172 | + | |
| 1173 | + | |
| 1174 | + | |
| 1175 | + | |
| 1176 | + | |
| 1177 | + | |
| 1178 | + | |
| 1179 | + | |
| 1180 | + | |
| 1181 | + | |
| 1182 | + | |
| 1183 | + | |
| 1184 | + | |
| 1185 | + | |
| 1186 | + | |
| 1187 | + | |
| 1188 | + | |
| 1189 | + | |
| 1190 | + | |
| 1191 | + | |
| 1192 | + | |
| 1193 | + | |
| 1194 | + | |
| 1195 | + | |
| 1196 | + | |
| 1197 | + | |
| 1198 | + | |
| 1199 | + | |
| 1200 | + | |
| 1201 | + | |
| 1202 | + | |
| 1203 | + | |
| 1204 | + | |
| 1205 | + | |
| 1206 | + | |
| 1207 | + | |
| 1208 | + | |
| 1209 | + | |
| 1210 | + | |
| 1211 | + | |
| 1212 | + | |
| 1213 | + | |
| 1214 | + | |
| 1215 | + | |
| 1216 | + | |
| 1217 | + | |
| 1218 | + | |
| 1219 | + | |
| 1220 | + | |
| 1221 | + | |
| 1222 | + | |
| 1223 | + | |
| 1224 | + | |
| 1225 | + | |
| 1226 | + | |
| 1227 | + | |
| 1228 | + | |
1133 | 1229 | | |
1134 | 1230 | | |
1135 | 1231 | | |
| |||
0 commit comments