Skip to content

Smarter download_artifacts tool#653

Open
jpodivin wants to merge 2 commits into
packit:mainfrom
jpodivin:smarter_download
Open

Smarter download_artifacts tool#653
jpodivin wants to merge 2 commits into
packit:mainfrom
jpodivin:smarter_download

Conversation

@jpodivin

@jpodivin jpodivin commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

The tool has been rewritten to allow less space for errors. Instead of letting agent choose where to download files to, which is also a security hazard, the agent can only choose what to download. Upon invocation, the tool creates a temporary directory, and all artifacts are downloaded there.

Path to the temporary directory is returned upon successful tool run. If the tool fails, the temporary directory and all contents are removed.

The cleanup step is, arguably, an overkill. Name of the temporary dir is generated randomly, and unless the agent were to get into a particularly vicious loop, it is unlikely to run out possible names.

The tool output has been written with custom get_text_content method, to cut down number of tokens used. It is very much a question of taste, as we are saving handful of tokens per call at best.

Fixes

PACKIT-5157: Download artifacts failing due to nonexistent directory

RELEASE NOTES BEGIN

The download_artifacts tool now uses temporary directories to store downloaded artifacts, and does not allow agent to choose where artifacts are downloaded.

RELEASE NOTES END

jpodivin added 2 commits July 3, 2026 16:31
Signed-off-by: Jiri Podivin <jpodivin@redhat.com>
Signed-off-by: Jiri Podivin <jpodivin@redhat.com>
@jpodivin jpodivin requested review from TomasKorbar and nforro July 3, 2026 14:41

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

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.

Code Review

This pull request refactors the DownloadArtifactsTool to automatically download artifacts to a dynamically created temporary directory instead of requiring a user-specified target_path. It also updates the tool output to return the temporary directory path as a JSON response and ensures cleanup of the directory in case of download failures. Feedback is provided to clean up the temporary directory created during successful test runs to prevent resource leaks.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +195 to 197
target_path = Path(result.target_path)
path = target_path / url.rsplit("/", 1)[-1].removesuffix(".gz")
assert path.read_bytes() == content

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

The unit test currently leaks the dynamically created temporary directory on successful runs. Since DownloadArtifactsTool now creates a temporary directory using tempfile.mkdtemp() and returns it, the test should ensure that this directory is cleaned up after assertions are complete.

Suggested change
target_path = Path(result.target_path)
path = target_path / url.rsplit("/", 1)[-1].removesuffix(".gz")
assert path.read_bytes() == content
import shutil
target_path = Path(result.target_path)
try:
path = target_path / url.rsplit("/", 1)[-1].removesuffix(".gz")
assert path.read_bytes() == content
finally:
shutil.rmtree(target_path, ignore_errors=True)
References
  1. Ensure temporary resources created during test execution are cleaned up to prevent resource leaks on the host system.

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.

1 participant