Skip to content

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

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

refactor(challenge): generalize hardcoded container prefixes and add WASM metadata to ChallengeConfig#25
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.

Summary by CodeRabbit

  • New Features

    • Added support for WebAssembly module metadata in challenge configurations for enhanced capability management.
  • Infrastructure Improvements

    • Implemented challenge-specific resource isolation to prevent data conflicts when running multiple concurrent challenge instances.
    • Optimized cleanup process to more efficiently manage resources across different challenge types and configurations.

…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

This pull request introduces challenge-specific slug-based volume naming in the Docker orchestrator, updates the cleanup API to accept a prefix parameter, and extends the ChallengeConfig data structure with a new optional WasmModuleMetadata field. Related tests are updated accordingly.

Changes

Cohort / File(s) Summary
Docker volume naming
crates/challenge-orchestrator/src/docker.rs
Replaced static volume names with dynamic, slug-derived volume names based on challenge configuration, updating volume creation, host bindings, and environment variable mappings.
Cleanup API changes
crates/challenge-orchestrator/src/lib.rs
Updated cleanup_stale_task_containers public function signature to accept a prefix: &str parameter; cleanup exclusion logic now uses the provided prefix for dynamic container name filtering.
Data model extension
crates/p2p-consensus/src/state.rs, tests/blockchain_state_tests.rs
Added wasm_module_metadata: Option<WasmModuleMetadata> field to ChallengeConfig struct; test initializations updated to include the new optional field.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 Volume slugs now dance with challenge names so grand,
Dynamic paths like carrots scattered through the land,
A prefix parameter helps cleanup find its way,
While WasmModuleMetadata joins the fray—
Refactored orchestration, perfectly planned! 🥕

🚥 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 captures 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

🧹 Nitpick comments (1)
crates/challenge-orchestrator/src/docker.rs (1)

732-735: cache_volume_name and dind_cache_volume may collide or cause confusion.

cache_volume_name (line 732) is "challenge-{slug}-cache" while dind_cache_volume (line 749) is "{slug}-cache". Both are created but serve different purposes. If someone names a challenge "challenge-foo", the cache volume becomes "challenge-challenge-foo-cache" and the DinD cache becomes "challenge-foo-cache" — these could overlap with another challenge named "foo". Consider using a consistent naming scheme to avoid ambiguity.

Also applies to: 747-750

🤖 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 732 - 735, The
cache volume naming is inconsistent and can collide: compute a single canonical
slug once (e.g., let slug = config.name.to_lowercase().replace(' ', '-')) and
then derive both names from it with distinct, explicit prefixes so their intent
is clear (e.g., "challenge-{slug}-cache" for challenge cache and
"dind-{slug}-cache" for the DinD cache); update the variables cache_volume_name
and dind_cache_volume (and any place that creates or refers to them) to use that
shared slug and the distinct prefixes to avoid collisions.
🤖 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 duplicated fragile slug logic
(config.name.to_lowercase().replace(' ', "-")) should be replaced by a single
helper (e.g., slugify) that normalizes the string once at the top of
start_challenge: lowercases, removes or replaces all characters not allowed in
Docker names (match [a-zA-Z0-9][a-zA-Z0-9_.-]*), collapses runs of invalid chars
to single hyphens, and trims leading/trailing separators; compute challenge_slug
= slugify(config.name) and then reuse that variable for container names and
volumes (tasks_volume, dind_cache_volume, evals_volume and any mounts/envs)
instead of repeating the inline replace.

---

Nitpick comments:
In `@crates/challenge-orchestrator/src/docker.rs`:
- Around line 732-735: The cache volume naming is inconsistent and can collide:
compute a single canonical slug once (e.g., let slug =
config.name.to_lowercase().replace(' ', '-')) and then derive both names from it
with distinct, explicit prefixes so their intent is clear (e.g.,
"challenge-{slug}-cache" for challenge cache and "dind-{slug}-cache" for the
DinD cache); update the variables cache_volume_name and dind_cache_volume (and
any place that creates or refers to them) to use that shared slug and the
distinct prefixes to avoid collisions.

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.

⚠️ Potential issue | 🟠 Major

Slug generation is fragile — only spaces are replaced, and the logic is duplicated.

The slug config.name.to_lowercase().replace(' ', "-") appears at lines 690, 734, and 747. Characters like /, .., \, or non-ASCII could produce invalid Docker volume names or introduce path traversal in mount paths (e.g., lines 782, 788, 834-836). Docker volume names must match [a-zA-Z0-9][a-zA-Z0-9_.-]*.

Consider:

  1. Extract a single slugify helper that strips or replaces all non-alphanumeric characters.
  2. Compute the slug once at the top of start_challenge and reuse it.
Proposed approach
+    /// Produce a Docker-safe slug from a challenge name.
+    fn slugify(name: &str) -> String {
+        name.to_lowercase()
+            .chars()
+            .map(|c| if c.is_ascii_alphanumeric() { c } else { '-' })
+            .collect::<String>()
+            .trim_matches('-')
+            .to_string()
+    }

Then at the top of start_challenge:

+        let challenge_slug = Self::slugify(&config.name);

And reuse challenge_slug everywhere (container name, cache volume, DinD volumes, env vars).

🤖 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
duplicated fragile slug logic (config.name.to_lowercase().replace(' ', "-"))
should be replaced by a single helper (e.g., slugify) that normalizes the string
once at the top of start_challenge: lowercases, removes or replaces all
characters not allowed in Docker names (match [a-zA-Z0-9][a-zA-Z0-9_.-]*),
collapses runs of invalid chars to single hyphens, and trims leading/trailing
separators; compute challenge_slug = slugify(config.name) and then reuse that
variable for container names and volumes (tasks_volume, dind_cache_volume,
evals_volume and any mounts/envs) instead of repeating the inline replace.

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