Skip to content

cubeapi: fix paused state parsing in sandbox list#270

Open
YangYuS8 wants to merge 1 commit into
TencentCloud:masterfrom
YangYuS8:fix/cubeapi-paused-list-state
Open

cubeapi: fix paused state parsing in sandbox list#270
YangYuS8 wants to merge 1 commit into
TencentCloud:masterfrom
YangYuS8:fix/cubeapi-paused-list-state

Conversation

@YangYuS8
Copy link
Copy Markdown
Contributor

Summary

  • Fix CubeAPI list status parsing for CubeMaster/Cubelet container state values.
  • Return paused for list entries whose CubeMaster status is CONTAINER_PAUSED (5).
  • Add a focused regression test for numeric and string paused list status values.

Fixes #218

Tests

  • cargo fmt --check
  • cargo +stable test
  • cargo +stable clippy --all-targets --all-features
  • Local HTTP verification with CubeAPI against a mock CubeMaster:
    • GET /sandboxes returns state: paused
    • GET /sandboxes/{id} still returns state: paused
    • GET /v2/sandboxes?state=paused returns the paused sandbox

Note: repo rust-toolchain 1.85.1 cannot run the current lockfile locally because time@0.3.47 requires rustc 1.88+.

Signed-off-by: YangYuS8 <YangYuS8@163.com>
@fslongjin
Copy link
Copy Markdown
Member

/cubebot review

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 15, 2026

Claude finished @fslongjin's task in 1m 12s —— View job


Review: cubeapi: fix paused state parsing in sandbox list (#270)

Summary

This PR fixes a bug where GET /sandboxes (sandbox list endpoint) did not return state: paused for sandboxes whose CubeMaster status code is 5 (CONTAINER_PAUSED). The fix adds the numeric code 5 to status normalization and its string representation "5" so that both JSON number and JSON string forms are correctly mapped to "paused".

What I reviewed

  • CubeAPI/src/cubemaster/mod.rssandbox_status_text_from_code, deserialize_sandbox_status, normalize_sandbox_status_text
  • CubeAPI/src/services/sandboxes.rsfrom_cubemaster_info, sandbox_state_from_str, and the new regression test

Data flow analysis

The fix touches the deserialization chain for SandboxInfo.status:

  1. JSON deserializationdeserialize_sandbox_status uses #[serde(untagged)] SandboxStatusValue to accept either a JSON number or string
  2. Number path: SandboxStatusValue::Number(5)sandbox_status_text_from_code(5)"paused"
  3. String path: SandboxStatusValue::Text("5")normalize_sandbox_status_text("5")"paused"
  4. Downstream: from_cubemaster_infosandbox_state_from_str("paused")SandboxState::Paused

Both paths correctly resolve to SandboxState::Paused.

Test coverage

The regression test (listed_sandbox_maps_paused_container_state_from_cubemaster_list) validates both the integer code 5 and the string "5" paths produce SandboxState::Paused for every entry. This is thorough and follows the existing test patterns in the codebase.

Minor observations (no action required)

  1. normalize_sandbox_status_text missing case for "3" (lines 893-902): sandbox_status_text_from_code maps code 3 to "unknown" via its catch-all, but normalize_sandbox_status_text doesn't have a "3" arm, so the string "3" falls through to other => other.to_string() and passes through as the literal string "3". This then hits the _ catch-all in sandbox_state_from_str and maps to SandboxState::Running — the same end result as the number path. Functionally identical, but adding an explicit "3" arm would make the two paths consistent.

  2. Normalize_sandbox_status_text other arm returns untrusted text (line 901): Unrecognized text values pass through verbatim via other => other.to_string(). This is actually fine for forward compatibility since sandbox_state_from_str (line 626) normalizes everything non-"paused" to Running, so no invalid state leaks to callers.

Verdict

Looks good. The changes are correct, minimal, and focused on the issue. The test exercises both JSON number and JSON string representations of the paused code. No correctness bugs or regressions found.

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.

[Bug Report] GET /sandboxes list API reports state as 'running' for paused sandboxes

2 participants