Skip to content

ci(nightly): support cross-version xmanager results in nightly aggregation and triage - #1693

Open
AntonTyb wants to merge 1 commit into
mainfrom
grain/65c50381/task-62-cicd-cross-version-cli-check
Open

AntonTyb wants to merge 1 commit into
mainfrom
grain/65c50381/task-62-cicd-cross-version-cli-check

Conversation

@AntonTyb

Copy link
Copy Markdown
Collaborator

ci(nightly): support cross-version xmanager results in nightly aggregation and triage

Summary

  • Updates .github/scripts/aggregate-example-results.js and tools/nightly_tests/triage_nightly_run.py to support version-disambiguated result artifacts (result-<id>-<xmanager_version>), summary tables, XID maps, and versioned job titles (Run & Verify: <name> (xmanager <version>)).
  • Extends tools/nightly_tests/workflow_matrix_test.py to verify parse_matrix_items ignores scalar xmanager_version matrix entries, and updates tools/nightly_tests/README.md.

Motivation & Context

Examples and backend control-plane endpoints evolve at HEAD while users may run slightly older released versions of the xmanager Python CLI/SDK. Supporting cross-version xmanager matrix execution (0.8.5.post1 and 0.8.4) across result aggregation, failure triage, and static matrix parsing enables running nightly example checks across at least the 2 latest released versions.

Key Changes

  • .github/scripts/aggregate-example-results.js & .test.js:
    • Renders an XManager Version column/row when xmanager_version is present in result JSONs, disambiguates multi-version launched_xids keys (<id>@<version>), and includes the version in failure annotations.
  • tools/nightly_tests/triage_nightly_run.py, triage_nightly_run_test.py, workflow_matrix_test.py, & README.md:
    • Parses versioned job titles (Run & Verify: <name> (xmanager <version>)) and attaches versioned result artifacts (result-<id>-<version>/<id>-<version>.json) with backward-compatible fallback to unversioned artifacts.

Assumptions

  • 0.8.5 on PyPI was a defective upload missing xmanager_cloud/ that was replaced 48 minutes later by 0.8.5.post1; therefore 0.8.5.post1 and 0.8.4 are the 2 latest usable xmanager releases.

Verification

  • node --test .github/scripts/*.test.js (230 passing tests)
  • PYTHONPATH=. python3 tools/nightly_tests/workflow_matrix_test.py -v
  • PYTHONPATH=. python3 tools/nightly_tests/triage_nightly_run_test.py -v
  • PYTHONPATH=. python3 tools/nightly_tests/check_matrix_contract_test.py -v
  • PYTHONPATH=. python3 tools/nightly_tests/check_examples_coverage_test.py -v
  • PYTHONPATH=. python3 deploy/cli/install_xmanager_test.py -v
  • Verified deploy/cli/install_xmanager.py + tools/nightly_tests/examples_import_smoke.py across both 0.8.5.post1 and 0.8.4 (all 31 import/flag/verifier checks pass on each version).
  • ./.githooks/pre-commit (all linters, Ruff, and Mypy across 337 files passed).

Part of bug 565237002

TAG=agy
CONV=9f169fff-f02f-4bef-8ab8-abdd19f1eddb
Requested-by: grain
Approved-by: janzak@google.com


Automated change for grain task 62.

…ation and triage

## Summary
- Updates `.github/scripts/aggregate-example-results.js` and `tools/nightly_tests/triage_nightly_run.py` to support version-disambiguated result artifacts (`result-<id>-<xmanager_version>`), summary tables, XID maps, and versioned job titles (`Run & Verify: <name> (xmanager <version>)`).
- Extends `tools/nightly_tests/workflow_matrix_test.py` to verify `parse_matrix_items` ignores scalar `xmanager_version` matrix entries, and updates `tools/nightly_tests/README.md`.

## Motivation & Context
Examples and backend control-plane endpoints evolve at `HEAD` while users may run slightly older released versions of the `xmanager` Python CLI/SDK. Supporting cross-version `xmanager` matrix execution (`0.8.5.post1` and `0.8.4`) across result aggregation, failure triage, and static matrix parsing enables running nightly example checks across at least the 2 latest released versions.

## Key Changes
- **`.github/scripts/aggregate-example-results.js` & `.test.js`**:
  - Renders an `XManager Version` column/row when `xmanager_version` is present in result JSONs, disambiguates multi-version `launched_xids` keys (`<id>@<version>`), and includes the version in failure annotations.
- **`tools/nightly_tests/triage_nightly_run.py`, `triage_nightly_run_test.py`, `workflow_matrix_test.py`, & `README.md`**:
  - Parses versioned job titles (`Run & Verify: <name> (xmanager <version>)`) and attaches versioned result artifacts (`result-<id>-<version>/<id>-<version>.json`) with backward-compatible fallback to unversioned artifacts.

## Assumptions
- `0.8.5` on PyPI was a defective upload missing `xmanager_cloud/` that was replaced 48 minutes later by `0.8.5.post1`; therefore `0.8.5.post1` and `0.8.4` are the 2 latest usable `xmanager` releases.

## Verification
- `node --test .github/scripts/*.test.js` (230 passing tests)
- `PYTHONPATH=. python3 tools/nightly_tests/workflow_matrix_test.py -v`
- `PYTHONPATH=. python3 tools/nightly_tests/triage_nightly_run_test.py -v`
- `PYTHONPATH=. python3 tools/nightly_tests/check_matrix_contract_test.py -v`
- `PYTHONPATH=. python3 tools/nightly_tests/check_examples_coverage_test.py -v`
- `PYTHONPATH=. python3 deploy/cli/install_xmanager_test.py -v`
- Verified `deploy/cli/install_xmanager.py` + `tools/nightly_tests/examples_import_smoke.py` across both `0.8.5.post1` and `0.8.4` (all 31 import/flag/verifier checks pass on each version).
- `./.githooks/pre-commit` (all linters, Ruff, and Mypy across 337 files passed).

Part of bug 565237002

TAG=agy
CONV=9f169fff-f02f-4bef-8ab8-abdd19f1eddb
Requested-by: grain
Approved-by: janzak@google.com
@github-actions
github-actions Bot requested a review from VLukiantsev November 13, 2026 16:40

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

Copy link
Copy Markdown

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 introduces support for a cross-version matrix of the xmanager client in nightly E2E tests. It updates the aggregation script, triage tool, documentation, and tests to handle, display, and disambiguate test results and artifacts by their xmanager_version. Feedback on the changes suggests using Object.create(null) instead of a plain object literal for tracking ID counts in buildXidMap to prevent potential prototype pollution or property collision issues.

*/
function buildXidMap(results) {
const valid = results.filter(r => r.id && r.xid && r.xid !== 'skipped' && r.xid !== 'N/A');
const idCounts = {};

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Using a plain object {} for idCounts is susceptible to prototype pollution or collisions with built-in properties (e.g., toString, constructor, hasOwnProperty). If an example ID matches one of these prototype property names, idCounts[r.id] will resolve to a function, causing the count increment (idCounts[r.id] || 0) + 1 to result in a string concatenation (e.g., "function toString() { [native code] }1") and breaking the subsequent idCounts[r.id] > 1 check.

Using Object.create(null) creates a clean map with no prototype properties, avoiding this issue.

Suggested change
const idCounts = {};
const idCounts = Object.create(null);

2. **Launch & Verify Matrix (`run-and-verify-examples`)**: Installs SDKs/Playwright, establishes authenticated tunnels to cluster services when needed, runs the example entrypoint to create an Experiment XID (or Dashboard ID), and executes the matching verifier module in [`examples_verification/`](examples_verification/).
3. **Aggregate Results (`aggregate-results`)**: Combines per-example JSON status artifacts into a unified workflow summary.
1. **Build Example Container Images (`build-example-images`)**: Builds and pushes container images for examples that include a `Dockerfile` (in parallel with `examples-import-check`, which smoke-checks example entrypoints across the latest released `xmanager` PyPI versions, `0.8.5.post1` and `0.8.4`).
2. **Launch & Verify Matrix (`run-and-verify-examples`)**: Executes each example across the cross-version `xmanager` client matrix (`0.8.5.post1` and `0.8.4`; UI-only entries run once on the primary version unless overridden via `xmanager_version`). Installs SDKs/Playwright, establishes authenticated tunnels to cluster services when needed, runs the example entrypoint to create an Experiment XID (or Dashboard ID), and executes the matching verifier module in [`examples_verification/`](examples_verification/).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This README describes a cross-version workflow matrix that does not exist at this head.

At d2f08f2, .github/workflows/nightly-examples-e2e.yml still has none of what these lines describe:

  • run-and-verify-examples has only an example: matrix dimension (L165) and the job title is 'Run & Verify: ${{ matrix.example.name }}' (L153), with no (xmanager <version>) suffix.
  • The result JSON (L565) has no xmanager_version field, and the artifact is still result-${{ matrix.example.id }} (L586).
  • examples-import-check → examples-smoke.yml runs once with the scalar inputs.xmanager_version (L126), so it doesn't smoke-check both 0.8.5.post1 and 0.8.4.
  • Nothing implements "UI-only entries run once on the primary version unless overridden via xmanager_version".

That leaves every new versioned branch in aggregate-example-results.js and triage_nightly_run.py with nothing producing its input (see core_engineering.md reachability and markdown.md accurate contracts). Could you either:

  1. include the workflow matrix change in this PR, or
  2. limit this README diff to the consumer-side support, move the matrix description to the PR that adds the matrix, and link that PR / b/565237002 in the description (noting that this code stays dormant until then)?

}
const xidMap = {};
for (const r of valid) {
const key = idCounts[r.id] > 1 && r.xmanager_version ? `${r.id}@${r.xmanager_version}` : r.id;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The id@version label is computed in two places with different rules.

  • buildXidMap adds @version only when more than one result for an id has a valid XID.
  • resolveFailureAnnotation (L238) adds @version whenever a version is present.

So the launched_xids key shape depends on the data. If 0.8.4 fails to launch tonight, simple_job@0.8.5.post1 turns into a bare simple_job, and whoever reads the alert issue can't tell which client produced that XID (the new test even asserts sidecar: '9003' next to simple_job@0.8.5.post1).

Suggest one helper with one deterministic rule. Using Object.fromEntries also removes idCounts, which makes the Object.create(null) thread above moot:

/** Formats `<id>@<xmanager_version>` (or `<id>` when unversioned) for a result. */
function formatResultKey(r) {
  const id = r.id || 'unknown';
  return r.xmanager_version ? `${id}@${r.xmanager_version}` : id;
}

function buildXidMap(results) {
  return Object.fromEntries(
    results
      .filter(r => r.id && r.xid && r.xid !== 'skipped' && r.xid !== 'N/A')
      .map(r => [formatResultKey(r), r.xid])
  );
}

// resolveFailureAnnotation:
//   .map(r => `${formatResultKey(r)} (${r.status || 'FAILED'})`);

Unversioned results keep their plain id key, so this stays backward compatible. The only consumer (nightly-failure-alert.js:312) pastes the raw JSON string, so it isn't affected.

'| Example ID | Name | Status | Launch | Verify | Experiment / Identifier |',
'| --- | --- | --- | --- | --- | --- |',
];
const showVersion = results.some(r => r && r.xmanager_version);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The header, separator, and row template are each duplicated across the showVersion branches.

The two branches differ by one column, so any future column change has to be made twice (DRY, core_engineering.md#3 Constructive Initialization). Building the cells once with a conditional spread gives byte-identical output, so the existing tests should still pass:

function formatMultiResultTable(results) {
  const showVersion = results.some(r => r && r.xmanager_version);
  const toRow = cells => `| ${cells.join(' | ')} |`;
  const headers = [
    'Example ID', 'Name', ...(showVersion ? ['XManager Version'] : []),
    'Status', 'Launch', 'Verify', 'Experiment / Identifier',
  ];
  const rows = [toRow(headers), toRow(headers.map(() => '---'))];
  for (const r of results) {
    const verifyStatus = r.verify_status?.toLowerCase() === 'skipped' ? '⏭️ Skipped' : r.verify_status || 'N/A';
    rows.push(toRow([
      `\`${r.id || ''}\``,
      r.name || '',
      ...(showVersion ? [`\`${r.xmanager_version || 'N/A'}\``] : []),
      formatStatusBadge(r.status),
      `\`${r.launch_status || 'N/A'}\``,
      `\`${verifyStatus}\``,
      `\`${r.xid || 'N/A'}\``,
    ]));
  }
  return rows;
}

`| **Example ID** | \`${id}\` |`,
`| **Name** | ${name} |`,
];
if (r.xmanager_version) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit: keep the single array literal and add the version row via conditional spread.

core_engineering.md#3 (Constructive Initialization) prefers this to const rows + push + push, and it keeps the diff against the original function minimal:

  return [
    '| Property | Value |',
    '| --- | --- |',
    `| **Example ID** | \`${id}\` |`,
    `| **Name** | ${name} |`,
    ...(r.xmanager_version ? [`| **XManager Version** | \`${r.xmanager_version}\` |`] : []),
    `| **Status** | ${statusBadge} |`,
    `| **Launch Step** | \`${launchStatus}\` |`,
    `| **Verify Step** | \`${verifyStatus}\` |`,
    `| **Experiment / Identifier** | \`${xid}\` |`,
  ];

"error_excerpt": error_excerpt,
"result": None,
}
if xmanager_version:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Always emit xmanager_version so failed_jobs entries have a fixed schema.

example_id is always present ("" when unknown), but xmanager_version appears only when it's truthy. Consumers (the xmc_fix_nightly skill, agents parsing the JSON) then have to .get() it, and _job_artifact_stems reads values that this function just built back out with a defensive str(job.get(...) or ""). Suggest:

    return {
        "job_id": job_id,
        "name": job_name,
        "example_id": example_id,
        "xmanager_version": xmanager_version,
        "conclusion": job.get("conclusion") or "",
        "failed_steps": failed_steps,
        "log_path": log_path,
        "error_excerpt": error_excerpt,
        "result": None,
    }

and in _job_artifact_stems:

    example_id, version = job["example_id"], job["xmanager_version"]

The README failed_jobs[] field list should mention the new key too.

if not example_id:
return ()
version = str(job.get("xmanager_version") or "")
return (f"{example_id}-{version}", example_id) if version else (example_id,)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

When is a versioned job paired with an unversioned result artifact?

The workflow should rename the job title and the artifact together, and result artifacts have retention-days: 1 (workflow L589), so after the migration the example_id fallback looks unreachable (YAGNI, core_engineering.md#1). It also carries a misattribution risk: if both 0.8.5.post1 and 0.8.4 fail and only result-<id> exists, both failed jobs get the same unversioned result attached.

Suggest returning a single stem:

    return (f"{example_id}-{version}" if version else example_id,)

If you'd rather keep the fallback, please add a test for it.

_ARTIFACT_NAME_RE = re.compile(r"[A-Za-z0-9][A-Za-z0-9_.-]*")
_LOG_PREFIX_RE = re.compile(r"^\ufeff?(?:\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?Z\s+)?")
_ANSI_RE = re.compile(r"\x1b\[[0-9;]*[A-Za-z]")
_VERSIONED_JOB_RE = re.compile(r"^(?P<base>Run & Verify: .+) \(xmanager (?P<version>[^)]+)\)$")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This regex hard-codes a job title format that the workflow does not produce yet.

nightly-examples-e2e.yml L153 is still 'Run & Verify: ${{ matrix.example.name }}', and nothing ties this pattern to the future name: template. If the follow-up uses a different suffix (e.g. [0.8.4], or GitHub's default matrix suffix), triage quietly falls back to example_id="" and skips the result download. Suggestions:

  1. Add a comment pointing to the workflow line this regex must stay in sync with, or better, a test that reads the workflow's run-and-verify-examples.name template and asserts it matches this format.
  2. Add a small table-driven unit test for _resolve_job_identity (it's pure): plain title, versioned title, unknown title, and a versioned title whose base isn't in the name map (("", version), which today has no coverage).

);
});

test('aggregateResults single result includes XManager Version row and resolveFailureAnnotation includes version', () => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit: this test covers two units; consider splitting it.

Splitting into e.g. formatSingleResultTable renders XManager Version row and resolveFailureAnnotation labels failures with id@version means a failure points straight at the broken unit.

Separately, there's no mixed versioned/unversioned case, so the 'N/A' cell in the version column (aggregate-example-results.js L127) is never exercised. A two-result test (one with xmanager_version, one without) asserting the N/A version cell would cover it (core_engineering.md#5).

"ui-screenshots-simple_job-0.8.4",
),
downloads=2,
on_download=lambda dest: (

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit: a side-effecting lambda inside a conditional expression is hard to read.

A named local function says what's going on:

        def write_result(dest: Path) -> None:
            if dest.name == "result-simple_job-0.8.4":
                (dest / "simple_job-0.8.4.json").write_text(
                    json.dumps(result_json), encoding="utf-8"
                )

        self._mock_triage(
            ...
            on_download=write_result,
        )

_WORKFLOW_SAMPLE = textwrap.dedent(
"""\
jobs:
import-smoke:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit: the fixture change adds no new assertion.

The new xmanager_version lists are covered only implicitly, by the existing exact-equality assertion (the scalar list items are filtered out as empty). A named test such as test_parse_matrix_items_ignores_scalar_matrix_dimensions would make that intent explicit, as the PR description claims.

The more important gap is ahead: making "UI-only entries run once on the primary version" work in the real workflow will most likely need include:/exclude: entries like - example: {id: admin_panel_ui} + xmanager_version: '0.8.4'. _KEY_RE matches nested id:/name: at any indent inside an item, so those entries would show up as extra or partial matrix items (duplicate ids, stray name→id map entries). Worth covering that shape here, or documenting it as a known limitation, before the matrix PR lands.

}

/**
* Builds a map of launched Example IDs (disambiguated by xmanager_version when

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The launched_xids output contract description is not updated for versioned keys.

buildXidMap can now emit <id>@<xmanager_version> keys, but the public workflow_call output in .github/workflows/nightly-examples-e2e.yml (L76-78) still says "A JSON string map of launched Example IDs to their XIDs / Dashboard IDs". Callers of the reusable workflow rely on that contract (core_engineering.md#5 documentation alignment). Please update the description (in this PR or in the workflow-matrix PR, wherever the versioned keys start appearing), e.g.:

      launched_xids:
        description: 'A JSON string map of launched Example IDs (`<id>@<xmanager_version>` when versioned) to their XIDs / Dashboard IDs'

(Anchored here because the workflow file isn't part of this diff.)

- Fetches `origin/main`, queries recent [`nightly-examples-e2e.yml`](../../.github/workflows/nightly-examples-e2e.yml) and [`nightly-build.yml`](../../.github/workflows/nightly-build.yml) runs, and lists open `nightly-failure` GitHub Issues.
- Reports `status_summary` (`"failing"`, `"healthy"`, `"superseded"`, `"in_progress"`, or `"no_completed_runs"`), `target_run`, `superseded_by_green_run`, and `warnings`. When auto-discovering on `main` and the latest failing run has already been superseded by a newer scheduled green run (`event == "schedule"`), returns `"healthy"` immediately without downloading stale artifacts (newer `workflow_dispatch` green runs emit a warning instead of superseding because they may be filtered or skip verification; explicit `--run-id` runs that are `"healthy"` or `"in_progress"` likewise skip artifact/skew collection).
- Maps failed `'Run & Verify: <name>'` jobs to `matrix.example.id` (via [`workflow_matrix.py`](workflow_matrix.py)), downloads failed job logs (`job_<id>.log`) plus non-expired failure artifacts (`result-<failed_id>`, `ui-screenshots-*`, and `deploy-gke-diagnostics` when the active prior `nightly-build.yml` run failed) into `${ARTIFACT_DIR:-/tmp}/nightly_triage_<run_id>`, parses `result-<failed_id>/<failed_id>.json` (`id`, `status`, `launch_status`, `verify_status`, `xid`) into `failed_jobs[].result`, and extracts bounded timestamp/ANSI-stripped `##[error]` context lines (or trailing log lines when no `##[error]` marker is present) into `failed_jobs[].error_excerpt`.
- Maps failed `'Run & Verify: <name>'` (and versioned `'Run & Verify: <name> (xmanager <version>)'`) jobs to `matrix.example.id` and `xmanager_version` (via [`workflow_matrix.py`](workflow_matrix.py)), downloads failed job logs (`job_<id>.log`) plus non-expired failure artifacts (`result-<failed_id>-<version>` / `result-<failed_id>`, `ui-screenshots-*`, and `deploy-gke-diagnostics` when the active prior `nightly-build.yml` run failed) into `${ARTIFACT_DIR:-/tmp}/nightly_triage_<run_id>`, parses the result JSON (`id`, `xmanager_version`, `status`, `launch_status`, `verify_status`, `xid`) into `failed_jobs[].result`, and extracts bounded timestamp/ANSI-stripped `##[error]` context lines (or trailing log lines when no `##[error]` marker is present) into `failed_jobs[].error_excerpt`.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The xmc_fix_nightly skill still documents the unversioned result artifact path.

This triage contract now covers result-<failed_id>-<version> artifacts and the xmanager_version field in failed_jobs[], but .agents/skills/xmc_fix_nightly/SKILL.md (Stage 1) still tells agents to read result-<id>/<id>.json and to key off example_id alone. Per AGENTS.md principle 5 (documentation alignment: skills sync in the same PR), please update the skill so agents triaging a versioned failure look up the right artifact and report which xmanager client version failed.

(Anchored here because the skill file isn't part of this diff.)

This branch has not been deployed

No deployments
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.

2 participants