Skip to content

refactor(challenge): generalize hardcoded container prefixes and add WASM metadata to ChallengeConfig#42

Open
echobt wants to merge 1 commit intomainfrom
refactor/generalize-container-prefixes-add-wasm-metadata
Open

refactor(challenge): generalize hardcoded container prefixes and add WASM metadata to ChallengeConfig#42
echobt wants to merge 1 commit intomainfrom
refactor/generalize-container-prefixes-add-wasm-metadata

Conversation

@echobt
Copy link
Contributor

@echobt echobt commented Feb 17, 2026

Summary

Removes hardcoded term-challenge- prefixes from Docker container/volume naming in the challenge orchestrator and adds optional WASM module metadata to ChallengeConfig in the consensus state, preparing for WASM-based challenge execution.

Changes

Challenge Orchestrator (crates/challenge-orchestrator)

  • docker.rs: Replace all hardcoded term-challenge- volume names and mount paths with dynamically generated names derived from config.name (slugified). This includes task volumes, cache volumes, eval volumes, and their corresponding environment variables (HOST_TASKS_DIR, HOST_CACHE_DIR, CACHE_DIR, HOST_BENCHMARK_RESULTS_DIR, BENCHMARK_RESULTS_DIR).
  • lib.rs: Parameterize cleanup_stale_task_containers to accept a prefix: &str argument instead of using the hardcoded term-challenge- prefix. Update the container exclusion list to use the dynamic prefix. Update tests accordingly.

P2P Consensus (crates/p2p-consensus)

  • state.rs: Add optional wasm_module_metadata: Option<WasmModuleMetadata> field to ChallengeConfig, with #[serde(default)] for backward compatibility. Import WasmModuleMetadata from platform_core.

Integration Tests

  • Update blockchain_state_tests.rs to include wasm_module_metadata: None in all ChallengeConfig instantiations.

Breaking Changes

  • cleanup_stale_task_containers now requires a prefix argument (previously took no arguments). Callers must be updated.

Continuation of closed PR #25.

Summary by CodeRabbit

  • Refactor

    • Docker volumes now dynamically named based on challenge identifiers instead of fixed names, improving isolation when running multiple challenges.
    • Cleanup operations updated to support challenge-specific scoping through configurable parameters.
  • New Features

    • Challenge configuration now supports optional WASM module metadata.

…WASM metadata to ChallengeConfig

Replace hardcoded "term-challenge-" Docker container name prefixes with
dynamic names derived from the challenge config name. This allows
multiple challenges to coexist without volume/container name collisions.

In challenge-orchestrator/docker.rs, volume names (tasks, cache, evals)
and their corresponding environment variables are now generated from a
slug of config.name instead of being hardcoded to "term-challenge-*".

In challenge-orchestrator/lib.rs, cleanup_stale_task_containers() now
accepts a prefix parameter so callers specify which challenge containers
to clean up, replacing the hardcoded "term-challenge-" prefix. The
exclude list is also dynamically constructed from the prefix.

In p2p-consensus/state.rs, ChallengeConfig gains an optional
wasm_module_metadata field (using WasmModuleMetadata from platform_core)
to support WASM-only challenges without requiring Docker configuration.
The field defaults to None via serde for backward compatibility.

Tests in blockchain_state_tests.rs and the orchestrator unit tests are
updated to match the new signatures and struct fields.
@coderabbitai
Copy link

coderabbitai bot commented Feb 17, 2026

📝 Walkthrough

Walkthrough

Docker volume naming now dynamically generates names using challenge name slugs instead of fixed identifiers. The container cleanup method gains a prefix parameter for scoped container removal. The ChallengeConfig struct extends to include an optional wasm module metadata field, with corresponding test updates.

Changes

Cohort / File(s) Summary
Docker Volume Naming
crates/challenge-orchestrator/src/docker.rs
Volume names for tasks, cache, and evals now derive from challenge name slug (lowercased, spaces replaced with hyphens) instead of fixed names. Environment variables and mount paths updated to reference these dynamic slug-based volume names.
Container Cleanup Scoping
crates/challenge-orchestrator/src/lib.rs
Method cleanup_stale_task_containers now accepts a prefix: &str parameter to scope cleanup to specific challenge prefixes. Container exclusion patterns dynamically updated to match challenge-{prefix}*. Tests updated with corresponding prefix argument and assertion expectations.
ChallengeConfig Extension
crates/p2p-consensus/src/state.rs, tests/blockchain_state_tests.rs
Added optional wasm_module_metadata: Option<WasmModuleMetadata> field to ChallengeConfig struct with serde(default) attribute. Import added for WasmModuleMetadata type. All test ChallengeConfig initializations updated to include wasm_module_metadata: None.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

🐰 Docker volumes now slug and slide,
With names derived from challenge pride,
Cleanup scopes by prefix thread,
And metadata fields, gently spread!
Dynamic naming saves the day,
In organized container way!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the two main changes: generalizing hardcoded container prefixes and adding WASM metadata to ChallengeConfig.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refactor/generalize-container-prefixes-add-wasm-metadata

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
crates/challenge-orchestrator/src/docker.rs (1)

730-743: ⚠️ Potential issue | 🟡 Minor

cache_volume_name is created but never mounted — orphan volume on every start.

The volume challenge-{slug}-cache (line 732) is created at line 741 but is not referenced in any bind mount. The actual cache mount at line 782 uses dind_cache_volume ({slug}-cache). This creates an unused Docker volume on every start_challenge call.

Either remove this dead volume creation or replace the DinD cache volume with it if it was meant to be the canonical cache volume.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@crates/challenge-orchestrator/src/docker.rs` around lines 730 - 743, The code
creates a volume using cache_volume_name and cache_volume_opts but never mounts
it, while the actual container bind uses dind_cache_volume, causing an orphaned
volume; fix by either removing the unused create_volume call or by using
cache_volume_name as the canonical cache volume when building the container
binds (replace references to dind_cache_volume with cache_volume_name in the
start_challenge container setup), ensuring the created volume is the one mounted
into the container and keeping variable names consistent (cache_volume_name,
cache_volume_opts, dind_cache_volume).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@crates/challenge-orchestrator/src/docker.rs`:
- Around line 747-750: The current slug construction using
config.name.to_lowercase().replace(' ', "-") (used where challenge_slug,
tasks_volume, dind_cache_volume, and evals_volume are built) only replaces
spaces and allows invalid chars into Docker volume names; add a reusable slugify
helper (e.g., slugify(name: &str) -> String) that lowercases, maps
non-alphanumeric chars to '-', collapses/trims leading/trailing '-' as needed,
and then replace the existing direct to_lowercase().replace(...) calls with
slugify(&config.name) when creating challenge_slug and the related volume names
so all non-alphanumeric characters are sanitized.

---

Outside diff comments:
In `@crates/challenge-orchestrator/src/docker.rs`:
- Around line 730-743: The code creates a volume using cache_volume_name and
cache_volume_opts but never mounts it, while the actual container bind uses
dind_cache_volume, causing an orphaned volume; fix by either removing the unused
create_volume call or by using cache_volume_name as the canonical cache volume
when building the container binds (replace references to dind_cache_volume with
cache_volume_name in the start_challenge container setup), ensuring the created
volume is the one mounted into the container and keeping variable names
consistent (cache_volume_name, cache_volume_opts, dind_cache_volume).

Comment on lines +747 to +750
let challenge_slug = config.name.to_lowercase().replace(' ', "-");
let tasks_volume = format!("{}-tasks", challenge_slug);
let dind_cache_volume = format!("{}-cache", challenge_slug);
let evals_volume = format!("{}-evals", challenge_slug);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

Slugification only handles spaces — other special characters will leak into Docker volume names.

config.name.to_lowercase().replace(' ', "-") leaves underscores, dots, colons, and other characters untouched. While Docker volume names are somewhat permissive ([a-zA-Z0-9][a-zA-Z0-9_.-]), challenge names with characters outside this set (e.g., my:challenge!) will produce invalid volume names. This same pattern is repeated at lines 690 and 734.

Consider extracting a proper slugify helper that strips or replaces all non-alphanumeric characters:

Suggested helper
fn slugify(name: &str) -> String {
    name.to_lowercase()
        .chars()
        .map(|c| if c.is_ascii_alphanumeric() { c } else { '-' })
        .collect::<String>()
        .trim_matches('-')
        .to_string()
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@crates/challenge-orchestrator/src/docker.rs` around lines 747 - 750, The
current slug construction using config.name.to_lowercase().replace(' ', "-")
(used where challenge_slug, tasks_volume, dind_cache_volume, and evals_volume
are built) only replaces spaces and allows invalid chars into Docker volume
names; add a reusable slugify helper (e.g., slugify(name: &str) -> String) that
lowercases, maps non-alphanumeric chars to '-', collapses/trims leading/trailing
'-' as needed, and then replace the existing direct to_lowercase().replace(...)
calls with slugify(&config.name) when creating challenge_slug and the related
volume names so all non-alphanumeric characters are sanitized.

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.

1 participant