Skip to content

feat(evaluator-sdk): skip re-execution if trial is present - #1040

Merged
ngoncharenko merged 2 commits into
mainfrom
ngoncharenko/aalgo-312-update-eval-cache
Aug 3, 2026
Merged

feat(evaluator-sdk): skip re-execution if trial is present#1040
ngoncharenko merged 2 commits into
mainfrom
ngoncharenko/aalgo-312-update-eval-cache

Conversation

@ngoncharenko

@ngoncharenko ngoncharenko commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Extract the evaluator SDK cache and resume work from feat(experimentalist): wire up nemo-evaluator-sdk using HarborRunner #955 into its own PR.
  • Fingerprint agent, task, and result-affecting configuration content before reusing Harbor job directories.
  • Preserve partial-trial resume with stable content-addressed agent imports and narrow recovery for Harbor resume refusals.
  • Keep the vendored Python SDK runtime mirror in sync.

Cache walkthrough

Why job_name was not enough

Old, broken cache key:

reuse the job directory if job_name matches
AND enough successful trials exist

Example failure:

Run 1: evaluate candidate-v1
       jobs/agent-0-train/ has 2 successful trials -> cached

Run 2: edit agent.py to candidate-v2, but keep the same job_name
       old logic sees 2 successful trials and skips Harbor
       -> candidate-v1 results are returned while candidate-v2 is being scored

The same stale-result hole existed when a task such as tests/test.sh changed, or when a result-affecting runtime option changed.

What the SDK stores

For a pinned job_name, the SDK writes a versioned stamp beside Harbor results:

jobs/agent-0-train/
  .nemo-eval-harbor-cache.json    <- digests of agent, tasks, and result-affecting options
  <trial>/result.json

The stamp covers the agent contents, the task contents and executable bits, and the HarborRuntimeConfig options that can change results. Runtime/build noise is excluded. If jobs_dir is nested inside the agent or dataset tree, that result subtree is excluded too; otherwise each completed run would change its own fingerprint and make the next run look stale.

Reuse, resume, or rerun

State SDK behavior
Stamp matches and every requested task has enough completed, non-errored attempts Serve the cached results without importing or running Harbor.
Stamp matches but coverage is incomplete Preserve the job directory and let Harbor resume only the missing trials.
Stamp is missing or mismatched Treat the directory as stale, discard it, and run fresh.
force_rerun=True Discard any existing directory and run fresh.
Harbor rejects an otherwise reusable directory with one of its recognized resume-refusal errors Log the relevant configuration drift, discard the directory, and retry once from clean state.
Any other FileExistsError Propagate the error and preserve the directory; unrelated failures never authorize deletion.

Callers choose whether to force a wipe. HarborAgentTaskRunner owns whether existing results are valid for the current inputs and whether incomplete work can resume. This keeps cache validity and per-task resume in the SDK rather than reimplementing them in each consumer.

Stable scoped agent imports

Harbor persists the agent import path in JobConfig and compares it before resuming. A random UUID in that path made an unchanged agent look different on every run, so partial resume was unreachable whenever agent_dir was used.

The import package name is now derived from an agent-content digest. Unchanged contents produce the same persisted import path; edited contents produce a different one. Identical agents can share that package name safely because overlapping scopes are reference-counted and removed only after the final scope exits. The same nested-jobs_dir exclusion used by the cache stamp is applied to this digest so accumulating results cannot move the import path. Symlink resolution failures, including loops on supported Python versions, degrade to a safe unresolved absolute path instead of crashing this best-effort guard.

Relationship to the Experimentalist PR

PR #955 targets this branch, so its diff contains only Experimentalist integration code. This change carries the cache/resume work previously merged into that feature branch through #964, plus the follow-up symlink-loop hardening.

Refs AALGO-312, AALGO-427, and AALGO-430.

Verification

  • uv run --frozen pytest packages/nemo_evaluator_sdk/tests/agent_eval -q: 475 passed, 1 skipped (real Harbor/Docker coverage included)
  • uv run --frozen ruff check packages/nemo_evaluator_sdk: passed
  • uv run --frozen ruff format --check packages/nemo_evaluator_sdk: 206 files already formatted
  • git diff --check origin/main...HEAD: passed

Summary by CodeRabbit

  • New Features

    • Added safer Harbor result caching that detects changed agents, tasks, and run options.
    • Improved resumable evaluations by preserving completed trials and rerunning only missing or outdated work.
    • Added diagnostics for cache status and configuration changes.
    • Custom agent imports now support excluded paths and deterministic reuse across overlapping scopes.
  • Bug Fixes

    • Harbor runs now recover safely when resume requests are refused or configuration has changed.
    • Improved handling of partial, malformed, and incomplete trial results.

Signed-off-by: Nick Goncharenko <ngoncharenko@nvidia.com>
@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

Harbor cache and resume reliability

Layer / File(s) Summary
Cache fingerprinting and lifecycle
packages/nemo_evaluator_sdk/src/nemo_evaluator_sdk/agent_eval/runtimes/harbor_runtime.py, packages/nemo_evaluator_sdk/tests/agent_eval/test_harbor_runtime.py
The runtime fingerprints cache inputs, validates stamps and task coverage, reuses complete jobs, resumes incomplete jobs, and writes stamps only when inputs remain unchanged.
Resume refusal and drift handling
packages/nemo_evaluator_sdk/src/nemo_evaluator_sdk/agent_eval/runtimes/harbor_runtime.py, packages/nemo_evaluator_sdk/tests/agent_eval/test_harbor_runtime.py
Harbor resume refusals trigger controlled cleanup and retry. Configuration drift diagnostics are persisted with bounded values.
Content-addressed agent imports
packages/nemo_evaluator_sdk/src/nemo_evaluator_sdk/agent_eval/runtimes/harbor_runtime.py, packages/nemo_evaluator_sdk/tests/agent_eval/test_harbor_runtime.py
Custom agent packages use deterministic content-derived names, excluded paths, reference counting, and scoped cleanup.
Partial-result adaptation and resume regression
packages/nemo_evaluator_sdk/tests/agent_eval/test_harbor_runtime.py, packages/nemo_evaluator_sdk/tests/agent_eval/test_harbor_runtime_e2e.py
Tests classify incomplete and malformed trial results and verify that resumed jobs preserve completed trials while rerunning missing trials.

Sequence Diagram(s)

sequenceDiagram
  participant NativeRunner
  participant JobDirectory
  participant Harbor
  participant TrialResults
  NativeRunner->>JobDirectory: Validate cache stamp and task coverage
  NativeRunner->>Harbor: Resume or execute the resolved job
  Harbor->>TrialResults: Write trial results
  NativeRunner->>JobDirectory: Adapt results and write the cache stamp
Loading

Possibly related PRs

Suggested reviewers: arpitsardhana, sandychapman, aleckhoury

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the PR's trial reuse behavior, which is a central part of the Harbor cache and resume changes.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ngoncharenko/aalgo-312-update-eval-cache

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai 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.

🧹 Nitpick comments (1)
packages/nemo_evaluator_sdk/src/nemo_evaluator_sdk/agent_eval/runtimes/harbor_runtime.py (1)

369-369: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Replace the string-based annotation.

"hashlib._Hash" is a string hint on a private typeshed-only symbol. The coding guidelines require concrete type hints. hashlib._Hash cannot be imported at runtime, so use a protocol you own or a concrete alias instead.

♻️ Proposed refactor
-def _feed(digest: "hashlib._Hash", label: bytes, payload: bytes) -> None:
+class _Digest(Protocol):
+    def update(self, data: bytes, /) -> None: ...
+
+
+def _feed(digest: _Digest, label: bytes, payload: bytes) -> None:

Add from typing import Protocol to the imports.

As per coding guidelines: "prefer concrete type hints over string-based type hints".

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@packages/nemo_evaluator_sdk/src/nemo_evaluator_sdk/agent_eval/runtimes/harbor_runtime.py`
at line 369, Replace the string annotation on _feed’s digest parameter with a
concrete runtime-safe type, such as an owned Protocol defining the hash
interface used by _feed; add the required typing import and avoid referencing
the private, typeshed-only hashlib._Hash symbol.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In
`@packages/nemo_evaluator_sdk/src/nemo_evaluator_sdk/agent_eval/runtimes/harbor_runtime.py`:
- Line 369: Replace the string annotation on _feed’s digest parameter with a
concrete runtime-safe type, such as an owned Protocol defining the hash
interface used by _feed; add the required typing import and avoid referencing
the private, typeshed-only hashlib._Hash symbol.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 2faf796d-1eed-4aac-93d1-3175cdaacd25

📥 Commits

Reviewing files that changed from the base of the PR and between 2cb9a08 and 3f6fb01.

⛔ Files ignored due to path filters (1)
  • sdk/python/nemo-platform/src/nemo_platform/beta/evaluator/agent_eval/runtimes/harbor_runtime.py is excluded by !sdk/**
📒 Files selected for processing (3)
  • packages/nemo_evaluator_sdk/src/nemo_evaluator_sdk/agent_eval/runtimes/harbor_runtime.py
  • packages/nemo_evaluator_sdk/tests/agent_eval/test_harbor_runtime.py
  • packages/nemo_evaluator_sdk/tests/agent_eval/test_harbor_runtime_e2e.py

@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor
Suite Lines Covered Line Rate Branch Rate
Unit Tests 30234/38242 79.1% 63.7%
Integration Tests 17879/36911 48.4% 20.9%

@ngoncharenko ngoncharenko changed the title feat(evaluator-sdk): add content-aware Harbor cache feat(evaluator-sdk): skip re-execution if trial is present Aug 3, 2026
@ngoncharenko
ngoncharenko enabled auto-merge August 3, 2026 18:23
@ngoncharenko
ngoncharenko added this pull request to the merge queue Aug 3, 2026
Merged via the queue into main with commit a0cb5f0 Aug 3, 2026
52 checks passed
@ngoncharenko
ngoncharenko deleted the ngoncharenko/aalgo-312-update-eval-cache branch August 3, 2026 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants