ROCK (Reinforcement Open Construction Kit)

repository·master·Indexed 19 days ago

https://github.com/alibaba/rock

A scalable environment management framework for agentic reinforcement learning. ROCK provides a client-server architecture to build, manage, and schedule sandboxed environments with varying levels of isolation. It includes a lightweight Job SDK that uses a bash protocol to execute commands in sandbox containers, decoupling training nodes from heavy dependencies like Docker or Harbor while supporting asynchronous execution and unified configuration.

Tokens
89.6K
Snippets
243
Records
380
Agent score
66%

What's inside ROCK

  1. Overview of TypeScript SDK core modules

    master

    The TypeScript SDK is organized into several functional modules aligned with the Python SDK capabilities:

    • Sandbox Core: Provides APIs for delete, restart, commit, and attach operations, along with error parsing and namespace/experiment management.
    • OSS Client: A standalone OssClient class for asynchronous persistence and two-layer OSS configuration parsing.
    • Speedup: Implements a strategy pattern using an executor and multiple strategy classes with pre-checks.
    • Agent: Includes RockAgent with support for Deploy.format, YAML loading, and integration with RuntimeEnv and ModelService.
    • EnvHub Datasets: Managed via DatasetClient, DatasetRegistry, and OssDatasetRegistry.
    • Job/Trial System: A comprehensive system for managing JobStatus, TrialResult, and various trial types like BashTrial, HarborTrial, and ComposeTrial using an Operator and JobExecutor.
    • Model Server: An Express-based server providing SSE (Server-Sent Events) encoding/decoding, trajectory recording via TrajectoryRecorder, and API routing (local and proxy modes).
  2. Understand the evaluation demo layout

    master

    The evaluation/ directory contains end-to-end demos that combine the sandbox lifecycle, agent installation/execution, and test suites. These are designed to show how individual components of ROCK fit together at the script level.

    One primary example is swe_bench/, which demonstrates a single-task SWE-bench Verified workflow:

    1. Starts a sandbox.
    2. Installs an agent using sandbox.agent.install().
    3. Runs the agent on a specific task.
    4. Executes the test suite.
    5. Parses the results.
  3. Overview of the Rock Job SDK Design

    master

    The Rock Job SDK is designed to solve integration issues between Reinforcement Learning (RL) training frameworks (like verl or SkyRL) and benchmarks (like Harbor).

    Instead of importing heavy Python SDKs (like the Harbor Python SDK) directly on the training node, the Job SDK uses the Rock bash protocol to execute commands inside a Rock sandbox container. This allows the training node to remain lightweight, only requiring the Rock SDK, while the heavy dependencies (Docker, Harbor, agent packages) run isolated within the sandbox.

    Key improvements over previous HTTP adapter methods:

    • Asynchronous Execution: Moves away from synchronous, blocking calls to an asynchronous model using Rock's nohup mode.
    • Decoupled Dependencies: Training nodes no longer need Harbor or Docker installed; they only need the Rock SDK.
    • Unified Configuration: Consolidates sandbox and benchmark configurations.
    • Full CLI Capability: Enables the use of full Harbor CLI commands (e.g., harbor jobs start) rather than being limited to Python API calls.
  4. Choose between evaluation demos and Harbor jobs

    master

    Deciding whether to use the evaluation/swe_bench/ scripts or the job/harbor/ framework depends on your goal:

    • Use evaluation/swe_bench/ (install-agent) when: You are debugging task setup or test parsing. These scripts provide full visibility into the entire pipeline in a single script form. It uses the Sandbox and sandbox.agent.install() APIs.
    • Use job/harbor/ (Job) when: You are performing production benchmark runs. This uses the Job(JobConfig.from_yaml(...)).run() API.
  5. Naming Conventions and Type Mapping

    master

    The SDK uses camelCase for all TypeScript interfaces and properties. While the underlying HTTP layer may use snake_case, the SDK automatically converts these to camelCase.

    Examples:

    • Use status.sandboxId, NOT status.sandbox_id.
    • Use result.exitCode, NOT result.exit_code.
    • Use result.failureReason, NOT result.failure_reason.
  6. Understand the new Job architecture (API Facade vs. Layered Implementation)

    master

    The ROCK Job architecture has transitioned from a monolithic Job class in bench/job.py to a layered, decoupled design. This allows for better separation of concerns between job orchestration, execution, and specific task logic (Trials).

    Architectural Layers

    • Job (Facade): A thin entry point (rock/sdk/job/api.py) that assembles the JobConfig and Operator.
    • Operator: Determines how many Trial instances to distribute (e.g., ScatterOperator).
    • Executor: Manages the lifecycle of the sandbox, handles parallel startup, and manages nohup processes (rock/sdk/job/executor.py).
    • Trial: Contains the specific task logic, including file uploads, script generation, and result parsing.
      • BashTrial: For simple bash commands.
      • HarborTrial: For Harbor-specific orchestration (rock/sdk/job/trial/harbor.py).
  7. VNC Proxy routing and behavior

    master

    The VNC Proxy is designed to provide a seamless interface for noVNC web clients. It operates with the following routing logic and constraints:

    Routing Logic

    • Target Port: The proxy is hardcoded to forward all traffic to port 8006 within the sandbox. It ignores any rock_target_port query parameters provided in the URL.
    • Path Passthrough: The [/{path}] segment allows the proxy to serve static files (e.g., core/rfb.js) required by the noVNC client.

    Error Handling

    • If the sandbox does not exist, the proxy returns a 404 error.
    • If the sandbox exists but port 8006 is unreachable, the proxy returns a 502 error.
  8. Configure Replay mode behavior

    master

    When running in Replay mode using --replay-file, the proxy behaves as follows:

    • Sequential Consumption: Each request consumes one record from the file. When the file ends, the proxy returns a 404.
    • Streaming Support: Replay mode simulates SSE chunks for streaming requests. It automatically injects the index field into tool_calls chunks to comply with the OpenAI streaming protocol.
    • Model Matching: If the model requested in the API call does not match the model in the recorded record, a warning is issued, but the request is not blocked.
    rock model-service start \
        --type proxy \
        --replay-file /tmp/rock-traj/LLMTraj.jsonl \
        --port 8081
  9. Compare VNC Proxy and General Proxy

    master

    Use the VNC Proxy (/proxy/vnc) instead of the General Proxy (/proxy) when specifically targeting VNC services. The primary difference is how ports are handled:

    | Feature | General Proxy (/proxy) | VNC Proxy (/proxy/vnc) | | :--- | :--- | : | | Port Specification | Via rock_target_port query param | Fixed to port 8006 | | Default Port | Port.SERVER = 8080 | N/A (Always 8006) | | Route Format | /proxy/{path} | /proxy/vnc/{path} | | WebSocket Support | Yes | Yes |

  10. How `rock job run` modes interact

    master

    The rock job run command operates under strict mutual exclusivity rules to ensure configuration clarity:

    • YAML vs. Flags: You cannot use --job_config at the same time as --script or --script-content.
    • Script vs. Content: In flags mode, you must choose either --script (a file path) or --script-content (an inline string). You cannot use both.
    • Harbor Requirements: Harbor jobs must be defined via a YAML configuration file (--job_config). They cannot be expressed purely via CLI flags.
    • Type Consistency: If you use the --type flag with a YAML file, the explicitly provided type must match the type detected in the YAML (e.g., if the YAML defines a BashJobConfig, --type must be bash).
  11. Understand the Dataset OSS path convention

    master

    ROCK enforces a strict hierarchical structure for datasets in OSS to ensure consistency across services. The path follows this pattern:

    oss://{bucket}/datasets/{organization}/{dataset_name}/{split}/{task_id}/

    ComponentDescriptionExample
    organizationThe owning organizationqwen
    dataset_nameThe name of the datasetmy-bench
    splitThe data split (e.g., train, test, v1.0)train
    task_idA unique directory for a specific benchmark tasktask-001

    Example Path: oss://my-bucket/datasets/qwen/my-bench/train/task-001/task.toml