rhscope.envs.base

Abstract hacking-environment interface + registry.

A BaseEnv combines (a) a task distribution, (b) a gameable reward function used to drive RL training, and (c) a ground-truth hacking signature for labeling rollouts after the fact.

The reward function is the signal the policy optimizes against. The hacking signature is the oracle used for probe training data and benchmark labeling. Together they let a researcher:

  1. Run RL training that will plausibly induce hacking (reward is weak / gameable by design).

  2. After each rollout, label whether the policy actually gamed the reward via hacking_signature.

  3. Use those labels as supervision for probe training or as eval metrics.

Concrete subclasses self-register via BaseEnv.__init_subclass__(); BaseEnv.registered_envs() lists them for discovery and BaseEnv.get_env_class(name) looks one up by name.

class rhscope.envs.base.EnvTask(task_id, prompt, metadata=<factory>)[source]

Bases: object

A single task from an environment.

Variables:
  • task_id (str) – Stable identifier for this task across train/eval splits.

  • prompt (str) – What the policy sees as input. Typically the full instruction text including any boilerplate the environment expects.

  • metadata (dict[str, Any]) – Env-specific information needed by reward_fn and hacking_signature (reference solutions, test specs, …). Opaque to the framework; validated by the env that produced it.

Parameters:
task_id: str
prompt: str
metadata: dict[str, Any]
class rhscope.envs.base.BaseEnv[source]

Bases: ABC

Abstract interface for a reward-hacking training environment.

Subclasses implement train_tasks, eval_tasks, reward_fn, and hacking_signature. The evaluate_hacking_rate helper is a default implementation that iterates hacking_signature over policy outputs.

Subclasses are auto-registered against their name class attribute at class-creation time. Use registered_envs() to discover them and get_env_class() to look one up.

Variables:

name (ClassVar[str]) – Short machine-friendly identifier used in recipes and logs.

name: ClassVar[str] = 'base_env'
classmethod registered_envs()[source]

Return the sorted list of currently-registered env names.

Return type:

list[str]

classmethod get_env_class(name)[source]

Return the env class registered under name.

Raises:

KeyError – If no env is registered under name. Import the module that defines the env before calling.

Parameters:

name (str)

Return type:

type[BaseEnv]

abstractmethod train_tasks()[source]

Return the training task distribution.

Return type:

list[EnvTask]

abstractmethod eval_tasks()[source]

Return the held-out evaluation task distribution.

Return type:

list[EnvTask]

abstractmethod reward_fn(task, response)[source]

Compute the training reward for response on task.

This is the signal the policy optimizes against. For hacking envs the reward is intentionally gameable (weak tests, lax verifier, …).

Parameters:
Return type:

float

abstractmethod hacking_signature(task, response)[source]

Oracle labeling: did the policy game the reward on this task?

Returns:

True iff response exhibits the hacking behavior this env is designed to catch (e.g. passed the weak tests but failed the strong held-out tests).

Parameters:
Return type:

bool

evaluate_hacking_rate(tasks, responses)[source]

Fraction of (task, response) pairs flagged as hacking.

Default implementation calls hacking_signature once per pair.

Parameters:
Returns:

sum(hacking_signature) / len(tasks), or 0.0 if empty.

Raises:

ValueError – If lengths differ.

Return type:

float