-
Notifications
You must be signed in to change notification settings - Fork 23
feat(agents): record which GitHub commit a deployment is running [ASTD-604] #2009
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
plugins/nemo-agents/src/nemo_agents_plugin/spec_revision.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| """Read the revision an agent's spec fileset is pinned to.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import logging | ||
| from collections.abc import Awaitable, Callable | ||
| from dataclasses import dataclass | ||
| from typing import TypeVar | ||
|
|
||
| from nemo_agents_plugin.entities import ethos_fileset_name | ||
| from nemo_platform import AsyncNeMoPlatform | ||
| from nemo_platform_plugin.client.adapter import client_from_platform | ||
| from nemo_platform_plugin.client.errors import NotFoundError as PluginClientNotFoundError | ||
| from nemo_platform_plugin.files.client import AsyncFilesClient | ||
| from nemo_platform_plugin.log_utils import sanitize_for_log | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
| T = TypeVar("T") | ||
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
| class SpecRevision: | ||
| revision: str = "" | ||
| tracked_revision: str = "" | ||
|
|
||
|
|
||
| async def read_spec_revision(files_client: AsyncFilesClient | None, *, workspace: str, agent_name: str) -> SpecRevision: | ||
| """Return what the agent's spec fileset is pinned to, or nothing if it cannot be read.""" | ||
| if files_client is None: | ||
| return SpecRevision() | ||
|
|
||
| fileset_name = ethos_fileset_name(agent_name) | ||
| try: | ||
| response = await files_client.get_fileset(workspace=workspace, name=fileset_name) | ||
| storage = response.data().storage | ||
| except PluginClientNotFoundError: | ||
| return SpecRevision() | ||
| except Exception: | ||
| logger.warning( | ||
| "Could not read fileset %s/%s for deployment provenance", | ||
| sanitize_for_log(workspace), | ||
| sanitize_for_log(fileset_name), | ||
| exc_info=True, | ||
| ) | ||
| return SpecRevision() | ||
|
|
||
| return SpecRevision(revision=storage.pinned_revision, tracked_revision=storage.tracked_revision or "") | ||
|
|
||
|
|
||
| def files_client_for(sdk: AsyncNeMoPlatform) -> AsyncFilesClient | None: | ||
| """Adapt the platform SDK, or None — a deployment must not fail for want of provenance.""" | ||
| try: | ||
| return client_from_platform(sdk, AsyncFilesClient) | ||
| except Exception: | ||
| logger.warning("Could not build a files client for deployment provenance", exc_info=True) | ||
| return None | ||
|
|
||
|
|
||
| async def stage_with_spec_revision( | ||
| files_client: AsyncFilesClient | None, | ||
| *, | ||
| workspace: str, | ||
| agent_name: str, | ||
| stage: Callable[[], Awaitable[T]], | ||
| ) -> tuple[T, SpecRevision]: | ||
| """Run *stage*, and report the revision the content it staged came from. | ||
|
|
||
| Reading the revision after the download would record a refresh that landed in | ||
| between, so restage once when it moves. | ||
| """ | ||
| if files_client is None: | ||
| return await stage(), SpecRevision() | ||
|
|
||
| before = await read_spec_revision(files_client, workspace=workspace, agent_name=agent_name) | ||
| staged = await stage() | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| after = await read_spec_revision(files_client, workspace=workspace, agent_name=agent_name) | ||
| if after == before: | ||
| return staged, after | ||
|
|
||
| logger.info( | ||
| "Spec fileset %s/%s moved from %r to %r while staging; staging it again", | ||
| sanitize_for_log(workspace), | ||
| sanitize_for_log(ethos_fileset_name(agent_name)), | ||
| before.revision, | ||
| after.revision, | ||
| ) | ||
| staged = await stage() | ||
| settled = await read_spec_revision(files_client, workspace=workspace, agent_name=agent_name) | ||
| if settled != after: | ||
| logger.warning( | ||
| "Spec fileset %s/%s moved again while staging; recording no revision for it", | ||
| sanitize_for_log(workspace), | ||
| sanitize_for_log(ethos_fileset_name(agent_name)), | ||
| ) | ||
| return staged, SpecRevision() | ||
| return staged, settled | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.