Repository navigation
fix(nightly): resolve WorkUnitState names from status_pb2 with synced fallback - #1652
Conversation
… 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
There was a problem hiding this comment.
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.
…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
There was a problem hiding this comment.
🤖 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.
|
grain is closing #1652 instead of merging it: its diff against Task 46 is marked done. |
fix(nightly): resolve WorkUnitState names from status_pb2 with synced fallback
Summary
Resolve
WorkUnitStatus.WorkUnitStateenum names directly fromstatus_pb2intools/nightly_tests/verification/xmc_entities_validator.pywhen the externalxmanager_cloudpackage is installed, and update the staticSTATE_NAMESfallback list to includeSCHEDULING_PAUSED(12) alongside a unit test that verifiesSTATE_NAMESagainstapi/protos/experiment/status.proto.Motivation & Context
tools/nightly_tests/verification/xmc_entities_validator.pymaintained a hand-copied list ofWorkUnitStatus.WorkUnitStatenames (0..11) so Bazel unit tests can run hermetically without the externalxmanager_cloudwheel. WhenSCHEDULING_PAUSED = 12was added toapi/protos/experiment/status.proto,state_enum_to_name(12)returned"UNKNOWN(12)"even whenxmanager_cloudwas installed, and no test guarded the fallback list against proto additions.Key Changes
status_pb2alongsideapi_pb2andpriority_pb2in the optionalxmanager_cloud.experiment_state_server.protoimport block intools/nightly_tests/verification/xmc_entities_validator.py.state_enum_to_nameto querystatus_pb2.WorkUnitStatus.WorkUnitState.Name(state_enum)(stripping theWORK_UNIT_STATE_prefix onWORK_UNIT_STATE_UNSPECIFIED) whenstatus_pb2is available, falling back toSTATE_NAMESonly whenstatus_pb2isNone."SCHEDULING_PAUSED"(12) toSTATE_NAMESand exportSTATE_SCHEDULING_PAUSEDintools/nightly_tests/verification/xmc_entities_validator.py.status.protoinapi/protos/experiment/BUILD.bazel, attachdata = ["//api/protos/experiment:status.proto"]toxmc_entities_validator_testintools/nightly_tests/verification/BUILD.bazel, and add unit tests intools/nightly_tests/verification/xmc_entities_validator_test.pycoveringstatus_pb2resolution, fallback lookup, and exact parity withstatus.proto.Assumptions
None — requirements were fully specified.
Verification & Testing
bazel test //tools/nightly_tests/verification:xmc_entities_validator_testXmcEntitiesValidatorTest(includingtest_state_enum_to_name,test_state_enum_to_name_with_proto_enum, andtest_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:
Automated change for grain task 46.