feat(design): screenshots-only viewer, list filtering, admin requeue - #70
Conversation
Viewer contract is screenshots-only: GET /v1/view/{id}/{page} serves
PNG artifacts (image/png) and answers 410 Gone with a JSON error for
.html/bare page names; bundle.json no longer embeds produced HTML
(410 Gone, use /v1/runs/{id}/pages for metadata). The gateway view
lockdown floor stays as defense in depth.
The public submissions list now keys on the captured screenshot:
design_submission returns None unless the run has index.png evidence
(screenshot_url field or pages list), so failed/no-artifact runs no
longer render dead view links. Submission.url becomes optional; design
rows drop the html url and keep screenshot_url only.
Operator escape hatch to (re)fill the current open round: loops list_active_harnesses and schedules each via the existing schedule_harness_for_round. Idempotent for the current round — a (harness, round) pair with runs returns its existing ids, so a second call creates nothing and consumes no quota; quota-blocked harnesses are reported under `skipped` without failing the rest. Bearer-protected via check_admin like candidates/winners and master-local by gateway policy (v1/admin/* is not proxied).
DESIGN_CHALLENGE.md §5/§6/§13: produced HTML is never served (was "raw HTML"); the viewer serves PNG screenshots only, .html requests and bundle.json return 410 Gone, and the CSP sandbox floor is now documented as the gateway-enforced defense-in-depth layer. Route tables updated, including POST /v1/admin/rounds/current/requeue. SITE_API.md and docs/external-miner/design.md synced to the new viewer/pages semantics; design-check pin raw_never_served renamed to html_never_served with the new wording.
📝 WalkthroughWalkthroughThe design viewer now serves PNG screenshots only. HTML and bundle responses return ChangesDesign delivery and requeue
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant AdminClient
participant admin_requeue_current
participant CurrentRound
participant ActiveHarnesses
AdminClient->>admin_requeue_current: POST /v1/admin/rounds/current/requeue
admin_requeue_current->>CurrentRound: Authenticate and load open round
admin_requeue_current->>ActiveHarnesses: Schedule active harnesses
ActiveHarnesses-->>admin_requeue_current: Return scheduled and skipped harnesses
admin_requeue_current-->>AdminClient: Return requeue report
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@crates/design-http/src/api.rs`:
- Around line 1351-1366: Replace the hard-coded admin token in
admin_requeue_schedules_current_round_once with a test-only value generated at
runtime, and use that value consistently when hashing and authenticating the
request. Do not log, document, or otherwise expose the generated token or any
full secret value.
- Around line 761-767: Update the PNG validation in the surrounding viewer
handler so it allows only the exact `index.png` artifact, rejecting every other
path or filename with the existing gone response; preserve successful serving
for `index.png`.
- Around line 949-981: Update schedule_harness_for_round to handle
StoreError::Duplicate from insert_run by re-reading the existing runs for the
harness and round and returning their run IDs as a successful scheduling result.
Preserve normal success behavior and continue propagating non-duplicate errors,
so concurrent requeue requests remain idempotent instead of marking the harness
skipped.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 603264b4-26a4-4607-b955-cf5f93564695
📒 Files selected for processing (9)
crates/design-http/src/api.rscrates/site-api/src/handlers.rscrates/site-api/src/map.rscrates/site-types/src/types.rsdocs/DESIGN_CHALLENGE.mddocs/DESIGN_CHALLENGE_CHECKLIST.mddocs/SITE_API.mddocs/external-miner/design.mdxtask/src/design_check.rs
| if !page.ends_with(".png") { | ||
| return json_err( | ||
| StatusCode::GONE, | ||
| "gone", | ||
| "produced HTML is never served; fetch the index.png screenshot instead", | ||
| ); | ||
| } |
There was a problem hiding this comment.
🔒 Security & Privacy | 🟠 Major | ⚡ Quick win
Allow only index.png.
Line 761 accepts every path ending in .png. A stored non-screenshot artifact can then become public through the viewer. This breaks the screenshots-only contract.
Proposed fix
- if !page.ends_with(".png") {
+ if page != "index.png" {📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if !page.ends_with(".png") { | |
| return json_err( | |
| StatusCode::GONE, | |
| "gone", | |
| "produced HTML is never served; fetch the index.png screenshot instead", | |
| ); | |
| } | |
| if page != "index.png" { | |
| return json_err( | |
| StatusCode::GONE, | |
| "gone", | |
| "produced HTML is never served; fetch the index.png screenshot instead", | |
| ); | |
| } |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@crates/design-http/src/api.rs` around lines 761 - 767, Update the PNG
validation in the surrounding viewer handler so it allows only the exact
`index.png` artifact, rejecting every other path or filename with the existing
gone response; preserve successful serving for `index.png`.
| async fn admin_requeue_current(State(st): State<Arc<AppState>>, headers: HeaderMap) -> Response { | ||
| if let Err(r) = check_admin(&st, &headers) { | ||
| return r; | ||
| } | ||
| let rid = round_id_at(now_secs()); | ||
| let harnesses = match st.store.list_active_harnesses(rid).await { | ||
| Ok(h) => h, | ||
| Err(e) => return json_err(StatusCode::INTERNAL_SERVER_ERROR, "store", &e.to_string()), | ||
| }; | ||
| let epoch = st.epoch.load(std::sync::atomic::Ordering::Relaxed); | ||
| let mut scheduled = Vec::new(); | ||
| let mut skipped = Vec::new(); | ||
| for harness in &harnesses { | ||
| match schedule_harness_for_round(st.store.as_ref(), harness, rid, st.netuid, epoch).await { | ||
| Ok(run_ids) => scheduled.push(json!({ | ||
| "harness_id": harness.id, | ||
| "miner_hotkey": harness.miner_hotkey, | ||
| "run_ids": run_ids, | ||
| })), | ||
| Err(e) => skipped.push(json!({ | ||
| "harness_id": harness.id, | ||
| "miner_hotkey": harness.miner_hotkey, | ||
| "reason": e, | ||
| })), | ||
| } | ||
| } | ||
| Json(json!({ | ||
| "round_id": rid, | ||
| "scheduled": scheduled, | ||
| "skipped": skipped, | ||
| })) | ||
| .into_response() | ||
| } |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
fd -t f -e rs . crates | while IFS= read -r file; do
ast-grep outline "$file" --items all --match 'DesignStore|insert_run|runs_for_round' || true
done
rg -n -C 5 'trait\s+DesignStore|fn\s+insert_run|fn\s+runs_for_round|INSERT INTO.*run|UNIQUE.*run' cratesRepository: BaseIntelligence/base
Length of output: 26201
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== api schedule_harness_for_round and admin_requeue_current =="
fd -a api.rs crates | while IFS= read -r file; do
echo "--- $file"
rg -n -C 8 'fn schedule_harness_for_round|admin_requeue_current|check_.*runs|#\(.*run' "$file" || true
done
echo "== db schema constraints for design_run =="
sed -n '1,120p' crates/db/migrations/0006_design_challenge.sql
echo "== design-db insert_design_run and runs_for_round =="
sed -n '440,540p' crates/design-db/src/lib.rs
sed -n '590,700p' crates/design-db/src/lib.rs
echo "== design-store implementations and errors =="
sed -n '300,365p' crates/design-store/src/store.rs
sed -n '230,285p' crates/design-store/src/dbstore.rs
echo "== deterministic schema/behavior probe =="
python3 - <<'PY'
import pathlib
p = pathlib.Path('crates/db/migrations/0006_design_challenge.sql')
text = p.read_text()
print('CREATE TABLE design_run exists:', 'CREATE TABLE design_run' in text)
print('CREATE TABLE design_run lines:')
tbl = []
collect = False
for line in text.splitlines():
if line.startswith('CREATE TABLE design_run'):
collect = True
if collect:
tbl.append(line)
if ');' in line:
break
print('\n'.join(tbl))
print('contains UNIQUE:', any('UNIQUE' in l for l in tbl))
print('contains PRIMARY KEY:', any('PRIMARY KEY' in l for l in tbl))
print('constraints:', [l.strip() for l in tbl if any(k in l for k in ('PRIMARY KEY', 'UNIQUE', 'CONSTRAINT', 'FOREIGN KEY', 'REFERENCES', 'NOT NULL'))])
for key in ('CREATE TABLE design_round', 'CREATE TABLE design_artifact', 'CREATE TABLE design_stage_event'):
print(f'{key} exists:', key in text)
PYRepository: BaseIntelligence/base
Length of output: 21444
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== schedule_harness_for_round implementation =="
sed -n '441,580p' crates/design-http/src/api.rs
echo "== StoreError variants and DB error mapping =="
rg -n -C 6 'enum StoreError|StoreError::.*Duplicate|map_db|impl From<DbError>|Backend' crates/design-store/src crates/design-http/src/api.rs
echo "== quota helpers =="
rg -n -C 5 'quota|daily|runs_allowed|quota_get|quota_bump|DesignStore' crates/design-http/src/api.rs crates/design-store/src/dbstore.rs crates/design-db/src/lib.rsRepository: BaseIntelligence/base
Length of output: 50377
🏁 Script executed:
#!/bin/bash
set -euo pipefail
python3 - <<'PY'
from pathlib import Path
import re
api = Path('crates/design-http/src/api.rs').read_text()
schema = Path('crates/db/migrations/0006_design_challenge.sql').read_text()
dbstore = Path('crates/design-store/src/dbstore.rs').read_text()
dbs_lib = Path('crates/design-db/src/lib.rs').read_text()
def between(s, start, end):
return s[s.index(start)+len(start):s.index(end)].strip()
schedule = between(api, 'pub async fn schedule_harness_for_round(', 'pub async fn get_harness')
print('schedule calls runs_for_round:', 'run_ids' in schedule and 'runs_for_round' in schedule)
print('schedule calls get_run before insert:', 'if store\n .get_run' in schedule)
print('schedule calls insert_run:', 'store.insert_run' in schedule)
print('schedule handles insert error:', re.search(r'store\.insert_run\(&row\)\.await\.map_err\(.*\)\?;', schedule) is not None)
print('insert handles duplicate later via get_run?', 'continue;' in schedule and 'return Err("' in schedule)
design_run = between(schema, 'CREATE TABLE design_run (', ');')
unique_ids = re.findall(r'UNIQUE\s*\((.*?)\)', design_run)
pk_ids = re.findall(r'PRIMARY\s+KEY(?:\s*\((.*?)(?:\)|\s+NOT))?', design_run)
print('design_run primary key:', 'id' in pk_ids)
print('design_run unique constraints:', unique_ids)
db_insert_call = re.search(r'impl\s+DesignStore\s+for\s+DbDesignStore\n\s*{(?P<body>.*?)\n}', dbstore, re.S).group('body')
print('DbDesignStore insert_run calls insert_design_run:', 'async fn insert_run' in db_insert_call and 'insert_design_run' in db_insert_call)
print('DbDesignStore insert_run maps errors:', '.map_err(map_db)' in db_insert_call)
map_db = re.search(r'fn\s+map_db\(.*?\n\{(?P<body>.*?)\n\}', dbstore, re.S).group('body')
print('map_db treats duplicate/unique as StoreError::Duplicate:', 'duplicate' in map_db and 'unique' in map_db and 'StoreError::Duplicate' in map_db)
insert_design_run_call = re.search(r'pub\s+async\s+fn\s+insert_design_run\([^;]+;', dbs_lib).group(0)
print('insert_design_run INSERT id only:', 'VALUES ($1' in insert_design_run_call and not 'ON CONFLICT' in insert_design_run_call)
PYRepository: BaseIntelligence/base
Length of output: 303
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== insert_design_run body =="
python3 - <<'PY'
from pathlib import Path
import re
dbs = Path('crates/design-db/src/lib.rs').read_text()
m = re.search(r'pub async fn insert_design_run\(.*?\n\}\n', dbs, re.S)
if not m:
# broader until next pub fn
start = dbs.index('pub async fn insert_design_run')
search = dbs[start:]
nexts = [search.index(p, 1) for p in ('\npub ', '\n[', '\n///')]
end = min(n for n in nexts if n > 0) if any(n > 0 for n in nexts) else len(search)
print('`#BEGIN`')
print(search[:end])
print('`#END`')
else:
print('`#BEGIN`')
print(m.group(0))
print('`#END`')
PY
echo "== behavior probe from source text =="
python3 - <<'PY'
from pathlib import Path
import re
api = Path('crates/design-http/src/api.rs').read_text()
schema = Path('crates/db/migrations/0006_design_challenge.sql').read_text()
dbstore = Path('crates/design-store/src/dbstore.rs').read_text()
dbs_lib = Path('crates/design-db/src/lib.rs').read_text()
start = api.index('pub async fn schedule_harness_for_round(')
end = api.index('\npub async fn get_harness(', start)
schedule = api[start:end]
print('schedule_checks_run_ids_from_round:', 'run_ids: Vec<String> = existing' in schedule and '..filter(|r| r.harness_id == harness.id)' in schedule)
print('schedule_returns_existing_run_ids:', 'if !run_ids.is_empty()' in schedule and 'return Ok(run_ids)' in schedule)
print('schedule_rechecks_each_run_id_before_insert:', re.search(r'if\s+store\s*\.[^\n]*get_run\(&run_id\).*?\.is_some\(\)\s*\{\s*run_ids\.push\(run_id\);', schedule, re.S) is not None)
print('schedule_inserts_run:', 'store.insert_run(&row).await.map_err' in schedule)
print('schedule_promotes_on_insert_success:', 'run_ids.push(run_id)' in schedule and 'store.quota_bump' in schedule)
run = schema[schema.index('CREATE TABLE design_run ('): schema.index('\n\nCREATE TABLE design_artifact', schema.index('CREATE TABLE design_run ('))]
print('design_run_primary_key_id:', re.search(r'id\s+TEXT\s+PRIMARY\s+KEY', run) is not None)
print('design_run_unique_constraints:', ',\n'.join(re.findall(r',?\s*(?:CONSTRAINT\s+\w+\s+)?\s*UNIQUE\s*\([^)]+\)', run, re.S)))
print('DbDesignStore_insert_run_uses_insert_design_run:', 'async fn insert_run' in dbstore and 'insert_design_run' in dbstore[dbstore.index('async fn insert_run'):dbstore.index('async fn get_run')])
print('DbDesignStore_maps_duplicate_errors:', 'if s.contains("duplicate") || s.contains("unique")' in dbstore and 'StoreError::Duplicate' in dbstore[dbstore.index('fn map_db'):dbstore.index('fn extras_from_value')])
print('insert_design_run_plain_insert_no_upsert:', 'fn map_db' not in dbs_lib[dbs_lib.index('pub async fn insert_design_run'):dbs_lib.index('/// Fetch run.')])
PYRepository: BaseIntelligence/base
Length of output: 715
🏁 Script executed:
#!/bin/bash
set -euo pipefail
python3 - <<'PY'
from pathlib import Path
import re
api = Path('crates/design-http/src/api.rs').read_text()
schema = Path('crates/db/migrations/0006_design_challenge.sql').read_text()
dbstore = Path('crates/design-store/src/dbstore.rs').read_text()
dbs_lib = Path('crates/design-db/src/lib.rs').read_text()
start = re.search(r'pub async fn schedule_harness_for_round\(', api).start()
end = re.search(r'(?::#\s*async fn get_harness)', api[start:]) or re.search(r'\n\nasync fn get_harness', api[start:])
schedule = api[start:api.index('\n\nasync fn get_harness', start)]
print('schedule_checks_run_ids_from_round:', 'run_ids: Vec<String> = existing' in schedule and 'filter(|r| r.harness_id == harness.id)' in schedule)
print('schedule_returns_existing_run_ids:', 'if !run_ids.is_empty()' in schedule and 'return Ok(run_ids)' in schedule)
print('schedule_rechecks_each_run_id_before_insert:', re.search(r'if\s+store\s*\.[^\n]*get_run\(&run_id\).*?\.is_some\(\)\s*\{\s*run_ids\.push\(run_id\);', schedule, re.S) is not None)
print('schedule_inserts_run:', 'store.insert_run(&row).await.map_err' in schedule)
print('schedule_promotes_on_insert_success:', 'run_ids.push(run_id)' in schedule and 'store.quota_bump' in schedule)
run = schema[schema.index('CREATE TABLE design_run ('): schema.index('\n\nCREATE TABLE design_artifact', schema.index('CREATE TABLE design_run ('))]
print('design_run_primary_key_id:', re.search(r'id\s+TEXT\s+PRIMARY\s+KEY', run) is not None)
print('design_run_unique_constraints:', ',\n'.join(re.findall(r',?\s*(?:CONSTRAINT\s+\w+\s+)?\s*UNIQUE\s*\([^)]+\)', run, re.S)))
insert_start = dbstore.index('async fn insert_run')
insert_end = dbstore.index('async fn get_run')
insert_chunk = dbstore[insert_start:insert_end]
print('DbDesignStore_insert_run_uses_insert_design_run:', 'insert_design_run' in insert_chunk)
print('DbDesignStore_maps_duplicate_errors:', 'if s.contains("duplicate") || s.contains("unique")' in dbstore[dbstore.index('fn map_db'):dbstore.index('fn extras_from_value')])
ins_start = dbs_lib.index('pub async fn insert_design_run')
ins_end = dbs_lib.index('/// Fetch run.', ins_start)
print('insert_design_run_plain_insert_no_upsert:', 'ON CONFLICT' not in dbs_lib[ins_start:ins_end])
PYRepository: BaseIntelligence/base
Length of output: 566
Handle run-insert races by reading existing runs after a duplicate error.
design_run only has id as a key, so insert_design_run is a plain insert and concurrent /requeue calls can both pass the empty per-round check. insert_run maps duplicate/unique DB errors to StoreError::Duplicate, but schedule_harness_for_round treats that as scheduling failure and reports the harness as skipped. On that error, re-read runs for (harness, round) instead of returning the error so the endpoint stays idempotent.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@crates/design-http/src/api.rs` around lines 949 - 981, Update
schedule_harness_for_round to handle StoreError::Duplicate from insert_run by
re-reading the existing runs for the harness and round and returning their run
IDs as a successful scheduling result. Preserve normal success behavior and
continue propagating non-duplicate errors, so concurrent requeue requests remain
idempotent instead of marking the harness skipped.
| async fn admin_requeue_schedules_current_round_once() { | ||
| let admin_token = "test-admin-token"; | ||
| let gating = Arc::new(MemoryGatingStore::new()); | ||
| let st = Arc::new(AppState { | ||
| store: Arc::new(MemoryDesignStore::new()), | ||
| epoch: std::sync::atomic::AtomicU64::new(0), | ||
| netuid: 541, | ||
| backend_mode: "memory", | ||
| annotator_token_hashes: vec![], | ||
| admin_token_hashes: vec![token_hash(admin_token)], | ||
| frame_ancestors: "'none'".into(), | ||
| retry_max: 2, | ||
| award_hook: None, | ||
| gating: Some(Arc::clone(&gating) as Arc<dyn GatingStore>), | ||
| metagraph: None, | ||
| }); |
There was a problem hiding this comment.
🔒 Security & Privacy | 🟡 Minor | ⚡ Quick win
Remove the literal bearer token.
Line 1352 embeds an operator bearer token in source. Generate a test-only value at runtime and do not print it.
As per coding guidelines, “Never log, document, or include evidence containing private keys, wallet mnemonics, API tokens, or full secret values.”
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@crates/design-http/src/api.rs` around lines 1351 - 1366, Replace the
hard-coded admin token in admin_requeue_schedules_current_round_once with a
test-only value generated at runtime, and use that value consistently when
hashing and authenticating the request. Do not log, document, or otherwise
expose the generated token or any full secret value.
Source: Coding guidelines
Summary
GET /v1/view/{id}/{page}now serves PNG artifacts only (image/png);.html/bare page names get410 Gonewith a short JSON error.GET /v1/runs/{id}/bundle.jsonno longer embeds produced HTML — also410 Gonewith a pointer to/v1/runs/{id}/pages(metadata) and/v1/view/{id}/index.png. Produced HTML is never served; the gateway view-lockdown header floor stays as defense in depth.design_submissionnow returnsNoneunless the run has a capturedindex.png(explicitscreenshot_urlor pages list), so failed/no-artifact runs no longer render dead view links on the public site.Submission.urlbecomesOption<String>; design rows drop the htmlurland keepscreenshotUrlonly (prism rows unchanged).POST /v1/admin/rounds/current/requeue(operator bearer, master-local like the otherv1/admin/*routes) schedules every active harness into the current open round via the existing idempotentschedule_harness_for_round; a second call is a no-op (same run ids, no quota burn), and quota-blocked harnesses are reported underskipped.DESIGN_CHALLENGE.md§5/§6/§13,SITE_API.md,docs/external-miner/design.md, and thedesign-checkpin (raw_never_served→html_never_served) updated to the screenshots-only wording.Decisions
bundle.jsona stripped-to-metadata body would byte-duplicate/v1/runs/{id}/pageswhile silently dropping the content callers actually wanted.floor(unix/8640)), complementing submit-time scheduling intoround+1.Test plan
view_page_serves_screenshots_only—.html/bare → 410 JSON (no HTML leak, no Set-Cookie),index.png→ 200image/pngbyte-exact, missing png → 404bundle_json_is_gone— 410, stored HTML not in bodyadmin_requeue_schedules_current_round_once— 401 without bearer; 2 harnesses scheduled into current round; second call identical + quota untoucheddesign_submission_requires_screenshot(map) +design_submissions_exclude_runs_without_screenshots(handler, wiremock) — html-only and detail-less runs excluded, html+png run includedcargo fmt --all -- --check,cargo clippy --workspace --all-targets -- -D warnings,cargo test --workspace(166 suites, 0 failures),xtask loc-cap(site-api 1481/1500),consensus-lint,spec-check,design-check,external-docs-check,cargo deny check— all greenDeploy note
Prod deploys from pins (
deploy/pins/prod.json), so this takes effect only after merge → tag → pin bump perdeploy/AGENTS.md. That is a follow-up, not part of this PR. Public miner docs PR forBaseIntelligence/design-challengeaccompanies this change.Summary by CodeRabbit
New Features
Changes
410 Gone.