Resolve #23: expose benchmark_codes and standardize task identity on (owner, repo, issue_number) - #24
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #23.
Summary
Lands everything
npm run syncneeds fromapi.formulacode.org, and folds in a cleanup the issue's discovery surfaced:task_idis constructed two incompatible ways across the codebase (owner__repo-Nin the publish/HF path vsowner_repo_Ninharbor_adapter), with neither matching the format the website assumed. Per the user directive, the canonical row identity is now(owner, repo, issue_number)everywhere, andtask_idbecomes a single-column integer mirror ofissue_number— kept for joins, no longer a derived string.What the website now gets (issue acceptance criteria)
benchmark_codespublic tablesupabase/migrations/00017_benchmark_codes.sql+ new stage 9task_idoncandidate_containerssupabase/migrations/00019_candidate_containers_task_id.sql(generated column =issue_number)CLAUDE.md"Level aggregation" subsection — geometric mean, 4 levels, with code citationbenchmark_typesupabase/migrations/00020_benchmark_information_type.sql(generated, derived from ASVtime_*/timeraw_*/mem_*/peakmem_*/track_*)New pipeline stage 9
scrape_benchmark_sourceWalks
candidate_containers, uses the existingprepare_repo_checkoutto materialize each repo at its SHA, then AST-parses everybenchmarks/*.py(or whateverasv.conf.jsondeclares asbenchmark_dir) to extract per-function source + colocatedsetup/setup_cache. Idempotent upsert intobenchmark_codes. Tunables:DATASMITH_BENCH_SCRAPE_MAX_FILE_BYTES,DATASMITH_BENCH_SCRAPE_DIRS.task_idcollapse — touched filesgithub/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 derivedtask_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
taskstable and snapshot bucket live in a different Supabase project — seeHARBOR_SUPABASE_URL. Two scripts handle the cross-project migration:scripts/harbor_tasks_migration.sql— addsowner/repo/issue_number, backfills from legacytask_id(handles both Format A and Format B), swaps the PK to the triple, retainstask_idas a deprecated integer mirror.scripts/migrate_snapshot_keys.py— walks Supabase Storage and movessnapshots/{old}/oracle.tar.gz→snapshots/{owner}/{repo}/{issue_number}/oracle.tar.gz. Defaults to--dry-run.Apply post-merge, in that order.
Breaking changes
tasksPK is now(owner, repo, issue_number). Any external consumer keying on legacytask_idstrings must read from the new columns. Thetask_idcolumn survives as an integer mirror so reads usingselect=task_idcontinue to work, just typed differently.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'sbenchmark_information.benchmark_nameis already param-stripped, so the website's1-Paramsrow is identical to datasmith'slevel1. Full description is inCLAUDE.mdunder "Level aggregation."Test plan
make checkclean (ruff, mypy, deptry)uv run pytest tests/scrape tests/publish tests/github— 108 passing, including new AST-extraction testsbenchmark_informationrows →time)scripts/harbor_tasks_migration.sql --dry-runagainst Harbor's Supabase and confirm the regex backfill parses every legacytask_idcleanlyscripts/migrate_snapshot_keys.py(dry run) and confirm the planned moves match the livetaskscountfc-data --stage 9 --start-date ...smoke run; confirmbenchmark_codespopulates and one row'ssourcematches the upstream file🤖 Generated with Claude Code