Skip to content

Commit fe1f24b

Browse files
Linux2010ishymko
andauthored
fix: raise on append=True for unknown artifact_id (#1038) (#1077)
## Problem `TaskUpdater.add_artifact(append=True, ...)` with an unknown `artifact_id` logs a warning and drops the chunk. The wire returns success while the streamed content is lost. ## Fix Raise instead of logging and dropping, with a message pointing the caller to create the artifact first (`append=False`). ## Tests Updated `test_append_artifact_to_task` to assert `ValueError` is raised and task artifacts are unchanged after the failed append. Fixes #1038 --------- Co-authored-by: Linux2010 <linux2010@users.noreply.github.com> Co-authored-by: Ivan Shymko <ishymko@google.com>
1 parent d2f2e18 commit fe1f24b

2 files changed

Lines changed: 18 additions & 12 deletions

File tree

src/a2a/server/tasks/task_manager.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
TaskStatus,
1313
TaskStatusUpdateEvent,
1414
)
15-
from a2a.utils.errors import InvalidParamsError
15+
from a2a.utils.errors import InvalidAgentResponseError, InvalidParamsError
1616
from a2a.utils.telemetry import trace_function
1717

1818

@@ -74,12 +74,16 @@ def append_artifact_to_task(task: Task, event: TaskArtifactUpdateEvent) -> None:
7474
dict(new_artifact_data.metadata.items())
7575
)
7676
else:
77-
# We received a chunk to append, but we don't have an existing artifact.
78-
# we will ignore this chunk
79-
logger.warning(
80-
'Received append=True for nonexistent artifact index %s in task %s. Ignoring chunk.',
81-
artifact_id,
82-
task.id,
77+
# A2A spec (Section 4.2.2 TaskArtifactUpdateEvent,
78+
# https://a2a-protocol.org/v1.0.0/specification/#422-taskartifactupdateevent):
79+
# "append — If true, the content of this artifact should be
80+
# appended to a previously sent artifact."
81+
# append=True with no prior artifact of this ID is an agent
82+
# protocol violation (#1038).
83+
raise InvalidAgentResponseError(
84+
f'append=True for nonexistent artifact_id={artifact_id!r} '
85+
f'in task {task.id!r}. The artifact must be created (append=False) '
86+
f'before appending parts to it.'
8387
)
8488

8589

tests/server/tasks/test_task_manager.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
TaskStatus,
1919
TaskStatusUpdateEvent,
2020
)
21-
from a2a.utils.errors import InvalidParamsError
21+
from a2a.utils.errors import InvalidAgentResponseError, InvalidParamsError
2222

2323

2424
class SampleUser(User):
@@ -429,6 +429,7 @@ def test_append_artifact_to_task():
429429
assert len(task.artifacts[1].parts) == 1
430430

431431
# Test appending part to a task that does not have a matching artifact
432+
# should raise InvalidAgentResponseError instead of silently dropping (#1038)
432433
non_existing_artifact_with_parts = Artifact(
433434
artifact_id='artifact-456', parts=[Part(text='Part 1')]
434435
)
@@ -438,7 +439,8 @@ def test_append_artifact_to_task():
438439
task_id='123',
439440
context_id='123',
440441
)
441-
append_artifact_to_task(task, append_event_5)
442-
assert len(task.artifacts) == 2
443-
assert len(task.artifacts[0].parts) == 2
444-
assert len(task.artifacts[1].parts) == 1
442+
with pytest.raises(
443+
InvalidAgentResponseError,
444+
match='append=True for nonexistent artifact_id',
445+
):
446+
append_artifact_to_task(task, append_event_5)

0 commit comments

Comments
 (0)