Skip to content

fix(nightly): resolve WorkUnitState names from status_pb2 with synced fallback - #1652

Merged
VLukiantsev merged 3 commits into
mainfrom
grain/65c50381/task-46-implement-http-b-569895806
Nov 12, 2026
Merged

VLukiantsev merged 3 commits into
mainfrom
grain/65c50381/task-46-implement-http-b-569895806

Conversation

@VLukiantsev

@VLukiantsev VLukiantsev commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

fix(nightly): resolve WorkUnitState names from status_pb2 with synced fallback

Summary

Resolve WorkUnitStatus.WorkUnitState enum names directly from status_pb2 in tools/nightly_tests/verification/xmc_entities_validator.py when the external xmanager_cloud package is installed, and update the static STATE_NAMES fallback list to include SCHEDULING_PAUSED (12) alongside a unit test that verifies STATE_NAMES against api/protos/experiment/status.proto.

Motivation & Context

tools/nightly_tests/verification/xmc_entities_validator.py maintained a hand-copied list of WorkUnitStatus.WorkUnitState names (0..11) so Bazel unit tests can run hermetically without the external xmanager_cloud wheel. When SCHEDULING_PAUSED = 12 was added to api/protos/experiment/status.proto, state_enum_to_name(12) returned "UNKNOWN(12)" even when xmanager_cloud was installed, and no test guarded the fallback list against proto additions.

Key Changes

  • Import status_pb2 alongside api_pb2 and priority_pb2 in the optional xmanager_cloud.experiment_state_server.proto import block in tools/nightly_tests/verification/xmc_entities_validator.py.
  • Update state_enum_to_name to query status_pb2.WorkUnitStatus.WorkUnitState.Name(state_enum) (stripping the WORK_UNIT_STATE_ prefix on WORK_UNIT_STATE_UNSPECIFIED) when status_pb2 is available, falling back to STATE_NAMES only when status_pb2 is None.
  • Add "SCHEDULING_PAUSED" (12) to STATE_NAMES and export STATE_SCHEDULING_PAUSED in tools/nightly_tests/verification/xmc_entities_validator.py.
  • Export status.proto in api/protos/experiment/BUILD.bazel, attach data = ["//api/protos/experiment:status.proto"] to xmc_entities_validator_test in tools/nightly_tests/verification/BUILD.bazel, and add unit tests in tools/nightly_tests/verification/xmc_entities_validator_test.py covering status_pb2 resolution, fallback lookup, and exact parity with status.proto.

Assumptions

None — requirements were fully specified.

Verification & Testing

  • Commands Executed: bazel test //tools/nightly_tests/verification:xmc_entities_validator_test
  • Coverage & Test Status: All 69 unit tests in XmcEntitiesValidatorTest (including test_state_enum_to_name, test_state_enum_to_name_with_proto_enum, and test_state_names_fallback_matches_status_proto) pass.

Related Issues / Bugs

Fixes bug b/569895806

Bug: b/569895806

TAG=agy
CONV=64ce2f30-ad8b-49fd-b7bc-e1a0c3311376

Requested-by: vluk@google.com
Approved-by: vluk@google.com

Also on this branch:

  • fix(nightly): fall back to STATE_NAMES on status_pb2 AttributeError or ValueError

Automated change for grain task 46.

VLukiantsev and others added 2 commits November 12, 2026 16:50
… fallback

## Summary
Resolve `WorkUnitStatus.WorkUnitState` enum names directly from `status_pb2` in `tools/nightly_tests/verification/xmc_entities_validator.py` when the external `xmanager_cloud` package is installed, and update the static `STATE_NAMES` fallback list to include `SCHEDULING_PAUSED` (`12`) alongside a unit test that verifies `STATE_NAMES` against `api/protos/experiment/status.proto`.

## Motivation & Context
`tools/nightly_tests/verification/xmc_entities_validator.py` maintained a hand-copied list of `WorkUnitStatus.WorkUnitState` names (`0..11`) so Bazel unit tests can run hermetically without the external `xmanager_cloud` wheel. When `SCHEDULING_PAUSED = 12` was added to `api/protos/experiment/status.proto`, `state_enum_to_name(12)` returned `"UNKNOWN(12)"` even when `xmanager_cloud` was installed, and no test guarded the fallback list against proto additions.

## Key Changes
- Import `status_pb2` alongside `api_pb2` and `priority_pb2` in the optional `xmanager_cloud.experiment_state_server.proto` import block in `tools/nightly_tests/verification/xmc_entities_validator.py`.
- Update `state_enum_to_name` to query `status_pb2.WorkUnitStatus.WorkUnitState.Name(state_enum)` (stripping the `WORK_UNIT_STATE_` prefix on `WORK_UNIT_STATE_UNSPECIFIED`) when `status_pb2` is available, falling back to `STATE_NAMES` only when `status_pb2` is `None`.
- Add `"SCHEDULING_PAUSED"` (`12`) to `STATE_NAMES` and export `STATE_SCHEDULING_PAUSED` in `tools/nightly_tests/verification/xmc_entities_validator.py`.
- Export `status.proto` in `api/protos/experiment/BUILD.bazel`, attach `data = ["//api/protos/experiment:status.proto"]` to `xmc_entities_validator_test` in `tools/nightly_tests/verification/BUILD.bazel`, and add unit tests in `tools/nightly_tests/verification/xmc_entities_validator_test.py` covering `status_pb2` resolution, fallback lookup, and exact parity with `status.proto`.

## Assumptions
None — requirements were fully specified.

## Verification & Testing
- **Commands Executed**: `bazel test //tools/nightly_tests/verification:xmc_entities_validator_test`
- **Coverage & Test Status**: All 69 unit tests in `XmcEntitiesValidatorTest` (including `test_state_enum_to_name`, `test_state_enum_to_name_with_proto_enum`, and `test_state_names_fallback_matches_status_proto`) pass.

## Related Issues / Bugs
Fixes bug b/569895806

Bug: b/569895806

TAG=agy
CONV=64ce2f30-ad8b-49fd-b7bc-e1a0c3311376

Requested-by: vluk@google.com
Approved-by: vluk@google.com
@github-actions
github-actions Bot requested a review from AntonTyb November 12, 2026 16:50

@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 updates the xmc_entities_validator tool to import and utilize status_pb2 for mapping WorkUnitState enum values to human-readable strings, while keeping a fallback list that includes the new SCHEDULING_PAUSED state. It also adds comprehensive unit tests to verify the fallback behavior and ensure alignment with status.proto. The review feedback suggests improving the robustness of state_enum_to_name by catching both AttributeError and ValueError when resolving names via status_pb2, allowing a graceful fallback to STATE_NAMES instead of returning an UNKNOWN string or crashing. A corresponding update to the test suite is also recommended to verify the fallback behavior correctly.

AntonTyb
AntonTyb previously approved these changes Nov 12, 2026
…r ValueError

Catch `(AttributeError, ValueError)` in `state_enum_to_name` and fall through to `STATE_NAMES` so older `xmanager_cloud` wheels lacking newer enum values still resolve from the synced fallback list, and update `test_state_enum_to_name_with_proto_enum` accordingly.

Comment link: #1652 (comment)
Comment link: #1652 (comment)
Bug: b/569895806

TAG=agy
CONV=64ce2f30-ad8b-49fd-b7bc-e1a0c3311376

Requested-by: vluk@google.com
Approved-by: vluk@google.com

@github-actions github-actions 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.

🤖 Incremental PR Approval

PR author is a code owner and changes since last approval (8 lines, excluding 10 test file lines) are within the 50-line grace delta.

Preserving prior approval by @AntonTyb on commit 1369c11.

@VLukiantsev
VLukiantsev added this pull request to the merge queue Nov 12, 2026
Merged via the queue into main with commit c7acb31 Nov 12, 2026
16 checks passed
@VLukiantsev

Copy link
Copy Markdown
Collaborator Author

grain is closing #1652 instead of merging it: its diff against main is empty. Everything this branch changes already landed on main as c7acb31 (fix(nightly): resolve WorkUnitState names from status_pb2 with synced fallback (#1652)), so merging it would only add an empty merge commit.

Task 46 is marked done.

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