Skip to content

fix: raise ValueError on append to nonexistent artifact#1040

Open
naveenkumarbaskaran wants to merge 1 commit intoa2aproject:mainfrom
naveenkumarbaskaran:fix/raise-on-append-unknown-artifact
Open

fix: raise ValueError on append to nonexistent artifact#1040
naveenkumarbaskaran wants to merge 1 commit intoa2aproject:mainfrom
naveenkumarbaskaran:fix/raise-on-append-unknown-artifact

Conversation

@naveenkumarbaskaran
Copy link
Copy Markdown

Summary

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.

Closes #1038

Changes

  • task_manager.py: Replace logger.warning + silent ignore with ValueError containing a descriptive message
  • test_task_manager.py: Updated existing test to assert the new ValueError behavior

Rationale

As described in #1038, the silent drop is a footgun for any server-side executor that doesn't already know the artifact_id-pinning pattern. This is Option 1 from the issue — the minimal/safest change. Loud failure beats silent drop.

Testing

Updated the existing test_append_artifact_to_task test case — the "append to nonexistent artifact" path now asserts pytest.raises(ValueError) and verifies artifacts remain unchanged.

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 a2aproject#1038
@naveenkumarbaskaran naveenkumarbaskaran requested a review from a team as a code owner May 2, 2026 16:49
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request modifies the task manager to raise a ValueError when attempting to append data to a non-existent artifact, replacing the previous behavior of silently logging a warning. The test suite has been updated to verify this new error-handling logic. The review feedback recommends using the project-specific InvalidParamsError instead of the built-in ValueError to ensure correct protocol mapping. Furthermore, the feedback highlights a repository rule requiring exception classes to be raised directly without instantiation, which requires adjustments to the implementation and the corresponding test assertions.

Comment on lines +81 to 85
raise ValueError(
f'append=True but no artifact with id {artifact_id!r} exists on '
f'task {task.id!r}. Create the artifact first (append=False) '
f'before appending to it.'
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider using InvalidParamsError instead of the built-in ValueError. Since append_artifact_to_task is part of the task event processing pipeline, using the project's custom A2AError subclasses ensures that the error is correctly caught and mapped to a structured protocol response. Note that per repository rules, exception classes must be raised directly without instantiation.

        raise InvalidParamsError
References
  1. Raise exception classes directly, without instantiating them (e.g., raise MyError instead of raise MyError()).

assert len(task.artifacts[1].parts) == 1

# Test appending part to a task that does not have a matching artifact
# raises ValueError instead of silently dropping the chunk (#1038)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

low

Update the comment to reflect the change to InvalidParamsError.

Suggested change
# raises ValueError instead of silently dropping the chunk (#1038)
# raises InvalidParamsError instead of silently dropping the chunk (#1038)

context_id='123',
)
append_artifact_to_task(task, append_event_5)
with pytest.raises(ValueError, match='append=True but no artifact with id'):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

low

Update the test to assert InvalidParamsError instead of ValueError to align with the implementation change. Note that the exception is raised without a message per repository rules.

Suggested change
with pytest.raises(ValueError, match='append=True but no artifact with id'):
with pytest.raises(InvalidParamsError):
References
  1. Raise exception classes directly, without instantiating them (e.g., raise MyError instead of raise MyError()).

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 2, 2026

🧪 Code Coverage (vs main)

⬇️ Download Full Report

No coverage changes.

Generated by coverage-comment.yml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: append=True with unknown artifact_id silently drops the chunk — should fail loudly

1 participant