Skip to content

Commit 5a72442

Browse files
fix: raise ValueError on append to nonexistent artifact
When `append_artifact_to_task()` receives `append=True` for an `artifact_id` that doesn't exist on the task, it previously logged a warning and silently dropped the chunk. This hid real bugs — callers saw a successful response with no content. Now raises `ValueError` with a clear message pointing at the bad call, making the misuse impossible to miss. Updated the existing test to assert the new ValueError behavior. Closes #1038
1 parent c0c6c08 commit 5a72442

2 files changed

Lines changed: 12 additions & 7 deletions

File tree

src/a2a/server/tasks/task_manager.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,14 @@ 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+
# We received a chunk to append, but there is no existing artifact
78+
# with this id. Silently dropping the chunk would hide a real bug
79+
# in the caller (e.g. generating a fresh artifact_id on every
80+
# add_artifact call instead of pinning one), so we raise.
81+
raise ValueError(
82+
f'append=True but no artifact with id {artifact_id!r} exists on '
83+
f'task {task.id!r}. Create the artifact first (append=False) '
84+
f'before appending to it.'
8385
)
8486

8587

tests/server/tasks/test_task_manager.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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+
# raises ValueError instead of silently dropping the chunk (#1038)
432433
non_existing_artifact_with_parts = Artifact(
433434
artifact_id='artifact-456', parts=[Part(text='Part 1')]
434435
)
@@ -438,7 +439,9 @@ 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+
with pytest.raises(ValueError, match='append=True but no artifact with id'):
443+
append_artifact_to_task(task, append_event_5)
444+
# Artifacts unchanged — the bad chunk was not silently added
442445
assert len(task.artifacts) == 2
443446
assert len(task.artifacts[0].parts) == 2
444447
assert len(task.artifacts[1].parts) == 1

0 commit comments

Comments
 (0)