Skip to content

Resolve #23: expose benchmark_codes and standardize task identity on (owner, repo, issue_number) - #24

Merged
atharvas merged 2 commits into
mainfrom
fix/issue-23-website-data-sync
May 11, 2026
Merged

Resolve #23: expose benchmark_codes and standardize task identity on (owner, repo, issue_number)#24
atharvas merged 2 commits into
mainfrom
fix/issue-23-website-data-sync

Conversation

@atharvas

Copy link
Copy Markdown
Member

Closes #23.

Summary

Lands everything npm run sync needs from api.formulacode.org, and folds in a cleanup the issue's discovery surfaced: task_id is constructed two incompatible ways across the codebase (owner__repo-N in the publish/HF path vs owner_repo_N in harbor_adapter), with neither matching the format the website assumed. Per the user directive, the canonical row identity is now (owner, repo, issue_number) everywhere, and task_id becomes a single-column integer mirror of issue_number — kept for joins, no longer a derived string.

What the website now gets (issue acceptance criteria)

Ask Where it lands
benchmark_codes public table supabase/migrations/00017_benchmark_codes.sql + new stage 9
Queryable task_id on candidate_containers supabase/migrations/00019_candidate_containers_task_id.sql (generated column = issue_number)
Level-aggregation statistic documented CLAUDE.md "Level aggregation" subsection — geometric mean, 4 levels, with code citation
Optional benchmark_type supabase/migrations/00020_benchmark_information_type.sql (generated, derived from ASV time_*/timeraw_*/mem_*/peakmem_*/track_*)

New pipeline stage 9 scrape_benchmark_source

Walks candidate_containers, uses the existing prepare_repo_checkout to materialize each repo at its SHA, then AST-parses every benchmarks/*.py (or whatever asv.conf.json declares as benchmark_dir) to extract per-function source + colocated setup / setup_cache. Idempotent upsert into benchmark_codes. Tunables: DATASMITH_BENCH_SCRAPE_MAX_FILE_BYTES, DATASMITH_BENCH_SCRAPE_DIRS.

task_id collapse — touched files

github/models.py, publish/records.py, publish/huggingface.py, publish/pipeline.py, harbor_adapter/{records,adapter,utils}.py, runners/harbor_healthcheck.py, harbor_adapter/template/{setup.sh,test.sh,upload.py,parser.py}. Harbor's directory layout uses a derived task_dir_name = f"{owner}__{repo}__{issue_number}" (still derived but contained to the adapter — Harbor's flat-dataset discovery requires it). All tests updated and passing.

One-shot migrations for Harbor's Supabase (NOT in supabase/migrations/)

Harbor's tasks table and snapshot bucket live in a different Supabase project — see HARBOR_SUPABASE_URL. Two scripts handle the cross-project migration:

  • scripts/harbor_tasks_migration.sql — adds owner/repo/issue_number, backfills from legacy task_id (handles both Format A and Format B), swaps the PK to the triple, retains task_id as a deprecated integer mirror.
  • scripts/migrate_snapshot_keys.py — walks Supabase Storage and moves snapshots/{old}/oracle.tar.gzsnapshots/{owner}/{repo}/{issue_number}/oracle.tar.gz. Defaults to --dry-run.

Apply post-merge, in that order.

Breaking changes

  • Harbor tasks PK is now (owner, repo, issue_number). Any external consumer keying on legacy task_id strings must read from the new columns. The task_id column survives as an integer mirror so reads using select=task_id continue to work, just typed differently.
  • Snapshot tarballs move under a deeper prefix; the script above renames existing ones.
  • Existing built Harbor containers still ship the old TASK_ID-only template — they'll write to the new path correctly but query the old PK shape. Rebuild on next harbor_healthcheck run.

Level-aggregation statistic (the website's open question)

Geometric mean. Code at src/datasmith/harbor_adapter/template/parser.py:158-204. Four levels: per-benchmark, per-class, per-module, overall. The website's CSV historically encodes five levels; datasmith's benchmark_information.benchmark_name is already param-stripped, so the website's 1-Params row is identical to datasmith's level1. Full description is in CLAUDE.md under "Level aggregation."

Test plan

  • make check clean (ruff, mypy, deptry)
  • uv run pytest tests/scrape tests/publish tests/github — 108 passing, including new AST-extraction tests
  • Migrations 00016 / 00017 / 00019 / 00020 applied locally; generated columns verified (35,152 benchmark_information rows → time)
  • Reviewer should: run scripts/harbor_tasks_migration.sql --dry-run against Harbor's Supabase and confirm the regex backfill parses every legacy task_id cleanly
  • Reviewer should: run scripts/migrate_snapshot_keys.py (dry run) and confirm the planned moves match the live tasks count
  • Reviewer should: fc-data --stage 9 --start-date ... smoke run; confirm benchmark_codes populates and one row's source matches the upstream file

🤖 Generated with Claude Code

atharvas and others added 2 commits May 11, 2026 11:56
Closes #23. The FormulaCode website's `npm run sync` script needs benchmark
source code, a queryable task identifier, the level-aggregation statistic,
and (optionally) `benchmark_type` exposed by `api.formulacode.org`. This
change lands all four, and along the way collapses the two competing
`task_id` string formats (`owner__repo-N` in publish, `owner_repo_N` in
harbor_adapter) into a single integer alias of `issue_number`, with
`(owner, repo, issue_number)` as the canonical row identity everywhere.

New Supabase tables / columns
- `benchmark_codes(owner, repo, benchmark_without_params, source, ...)` —
  public-read; populated by stage 9.
- `candidate_containers.task_id` — generated column = issue_number.
- `benchmark_information.benchmark_type` — generated column derived from
  the ASV `time_*`/`timeraw_*`/`mem_*`/`peakmem_*`/`track_*` convention.

New pipeline stage 9 `scrape_benchmark_source`
- Reuses `prepare_repo_checkout` / AST traversal under each repo's
  `benchmark_dir` (resolved from `asv.conf.json` when present) to extract
  per-function source + co-located `setup` / `setup_cache`.
- Idempotent upsert keyed on (owner, repo, benchmark_without_params).
- Tunables: `DATASMITH_BENCH_SCRAPE_MAX_FILE_BYTES`,
  `DATASMITH_BENCH_SCRAPE_DIRS`.

task_id collapse
- `FormulaCodeRecord.task_id` is now `int` = `issue_number` across
  `github.models`, `publish.records`, `publish.huggingface`, and
  `harbor_adapter.{records,adapter,utils,template/*}`.
- Harbor templates pass `OWNER`/`REPO`/`ISSUE_NUMBER` to `upload.py` /
  `parser.py`; storage layout moves from `snapshots/{task_id}/...` to
  `snapshots/{owner}/{repo}/{issue_number}/...`; Supabase queries on the
  `tasks` table switch to a composite filter.
- Harbor task directory layout uses a derived `task_dir_name`
  (`owner__repo__issue_number`) so Harbor's flat-dataset discovery and
  trial-name patching keep working.

Companion scripts (apply once against Harbor's Supabase, not datasmith's)
- `scripts/harbor_tasks_migration.sql` — backfill `owner/repo/issue_number`
  from legacy task_id strings, swap the PK to the triple, retain
  `task_id` as a deprecated mirror.
- `scripts/migrate_snapshot_keys.py` — rename existing
  `snapshots/{old_task_id}/oracle.tar.gz` objects under the new prefix.
  Defaults to `--dry-run`; pass `--apply` to commit.

Docs
- CLAUDE.md gains the new table, stage 9, tunables, and a "Level
  aggregation" subsection documenting the geomean rollup
  (`harbor_adapter/template/parser.py:158-204`) — the answer the issue
  explicitly asks for.

Verification
- `make check` clean (ruff + mypy + deptry).
- `pytest tests/scrape tests/publish tests/github` — 108 passing,
  including a new AST-extraction test against an inline ASV fixture.
- Migrations 00016/00017/00019/00020 applied locally; schema introspection
  confirms generated columns produce expected values (35,152
  benchmark_information rows resolved to `time`).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This branch adds `resolve_packages` as a new pipeline stage, bringing the
total from 8 to 9. The website-snippet test was still asserting the old
count.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@atharvas
atharvas merged commit 923734d into main May 11, 2026
3 checks passed
@atharvas
atharvas deleted the fix/issue-23-website-data-sync branch May 11, 2026 22:54
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.

Expose benchmark code, task IDs, and level-aggregation spec for the website data sync

1 participant