Skip to content

optimize: fix corpus corruption, make CI link check real, remove dead code - #37

Merged
aaronjmars merged 9 commits into
mainfrom
optimize/cleanup
Jul 21, 2026
Merged

optimize: fix corpus corruption, make CI link check real, remove dead code#37
aaronjmars merged 9 commits into
mainfrom
optimize/cleanup

Conversation

@aaronjmars

Copy link
Copy Markdown
Collaborator

Ran the 8-agent /optimize sweep over the repo. Five agents applied (dedup, dead-code, defensive-code, legacy-paths, ai-slop); type-consolidation, circular-deps and weak-types were skipped as inapplicable — no typed language, no module graph, no dependency manifest.

One commit per domain so any dimension can be reverted independently.

The headline: three committed data files were corrupt

karpathy/scripts/fetch-data.sh used curl -sL without -f, so HTTP errors were written to disk as the response body and curl still exited 0 — the author's own || echo "[WARN]" could never fire, and the [ -f ] cache guard meant the poisoned file was never retried.

Verified against the live URL: curl -sL exits 0 and writes a 9379-byte 404 page; curl -fsSL exits 56 and writes nothing.

File Was Now
data/writing/software-2.0.html 9379 B GitHub Pages 404 241 KB real essay
data/github/karpathy_char-rnn_README.md 14 B 404: Not Found 12.8 KB real README
data/x/steipete.replies.json [] (2 B) still [] — needs a SURF_API_KEY re-pull

The first one mattered most: SOUL.md:20 calls Software 2.0 "my core thesis" and weak-model-test.mjs:239 scores model output for that literal string — so the grounding for the file's central claim was a 404 page. The URL was simply wrong (the essay is on Medium). char-rnn ships Readme.md, not README.md.

Sources were fixed before re-fetching, so a pipeline re-run reproduces the good files. Swept all of examples/*/data for other empty or error-body files: none.

The CI job named "Check relative links" checked nothing

scripts/check-links.mjs scanned only root-level *.md — five files containing zero relative links. It printed ✓ 0 relative link(s) across 5 doc(s) and passed unconditionally. Cause: 9edda35 moved README/CONTRIBUTING/SECURITY into .github/ and the scope was never updated, so its own comment named the exact failure mode it could no longer see.

Now scans root + .github/ + folder guides + per-example README/QUICKSTART, still excluding examples/*/data/ and persona files. 22 links across 20 docs. Verified it fails correctly by injecting a broken link (exits 1, names the target).

Also fixed

  • SURF_API_KEY vs SURF_AI_API_KEYpull-x.mjs reads the former, fetch-data.sh and the README passed the latter, so following the documented instructions hit exit(1). That pipeline had never run. Unified across 11 sites.
  • Stale star counts — all 9 rows in the frameworks table were understated. Verified against the GitHub API: OpenClaw 322k→383k, Hermes Agent 8.7k→218k (checked for a redirect; none), and 6 others. Re-sorted.
  • Dead code — unused dirname import, HANDLE const, _slug() plus the re import it was the sole consumer of.
  • Silent failures — bare || true, discarded yt-dlp stderr, a swallowed MCP protocol violation, errors on stdout instead of stderr, and run_weak_model.py writing [ERROR 401: ...] into a results file as if it were the model's answer, then exiting 0.
  • Broken idempotency — the transcript cache checked for .vtt files when zero are committed, so every transcript re-downloaded on every run.
  • Stale docssoul-builder pointed at SKILL.md (it's BUILD.md); a documented test command that could not run; a "live run pending" status for a run that shipped 2026-04-14; README trees documenting directories that don't exist; a 40-line embedded "reference implementation" contradicting the real script.
  • −48 lines collapsing byte-identical openai/openrouter fetch branches.

Deliberately not done

  • No cross-persona consolidation despite a 24.76% JS clone rate. Each examples/<persona>/ folder is meant to be copied out whole, and what would need parameterizing (12 prompts, system prompt, scoring regexes) is the persona. The two fetch-data.sh files scored 0 clones — independently written, not copy-paste.
  • No persona prose touched. SOUL.md, STYLE.md, good-outputs.md are the product; bad-outputs.md contains deliberately bad writing as negative examples.
  • examples/*/data/** untouched apart from the two repairs. Its 164 "broken" links are third-party source material pointing at original repo layouts — correct by design.

Verification

Gate after every domain: node --check ×4, bash -n ×2 (+ shellcheck), python3 -m py_compile ×4, node scripts/check-links.mjs, markdownlint-cli2. All green, no new failures vs. the 5cc4a00 baseline.

Scripts were not executed end-to-end — they hit paid APIs and need credentials. The riskiest edit is the fetch-branch collapse; the two branches were confirmed byte-identical apart from the URL and output stays in scope, but it hasn't run against a live API.

- pull-x.mjs: drop unused `dirname` import
- fetch_x.py: drop unused HANDLE constant and _slug() (and the now-orphaned
  `re` import that _slug was the sole consumer of)
- weak-model-test.mjs: write results to tests/, not examples/ — the file has
  only ever lived in tests/, all three docs point there, and the steipete
  twin already does this correctly
- karpathy/README.md: ../../pull-x.mjs did not exist; point at its real home
- .gitignore: add __pycache__/ and *.pyc (the repo's own documented verify
  command generates them)
- CONTRIBUTING/SECURITY: the soul-builder skill is BUILD.md, not SKILL.md.
  Fossil from when SKILL.md was deleted (0800de6) and later re-added in a
  different role (d750ab3); both docs were written against the middle state.
- BUILD.md: list examples/bad-outputs.md in Output — the template exists and
  both README and CONTRIBUTING require it.
- garry-tan/weak_model_test.md: the documented command could not run (no
  --prompts flag; --style/--good/--bad are required). Replaced with the
  verified invocation from scores_gpt-4o-mini.md.
- garry-tan/weak_model_test.md: Status claimed the live run was pending; it
  shipped 2026-04-14 at 38.5/48. Corrected, and 13 prompts -> 12 (48 max / 4).
karpathy/fetch-data.sh used `curl -sL` without -f, so HTTP errors were written
to disk as the response body and curl still exited 0 — the author's own
`|| echo "[WARN]"` could never fire, and the `[ -f ]` cache guard meant the
poisoned file was never retried. Verified against the live URL: `curl -sL`
exits 0 and writes a 9379-byte 404 page; `curl -fsSL` exits 56 and writes
nothing.

This already corrupted three committed files (data fix is separate):
- data/writing/software-2.0.html      -> GitHub Pages 404 (9379 B)
- data/github/karpathy_char-rnn_README.md -> "404: Not Found" (14 B)
- steipete data/x/steipete.replies.json   -> [] (2 B)

Changes:
- karpathy/fetch-data.sh: -sL -> -fsSL --max-time 30 on both fetch sites;
  cache guards now also test -s. This also revives the master->main README
  fallback, which was unreachable because the first curl never failed.
- karpathy/fetch-data.sh: stop discarding yt-dlp stderr; "No subs" was
  asserted for what may have been a network or geo failure.
- steipete/fetch-data.sh: bare `|| true` -> report the failure.
- pull-x.mjs: a non-JSON line on the MCP stdout channel is a protocol
  violation; log it instead of discarding it silently.
- both weak-model-test.mjs: send errors to stderr, not stdout.
Both weak-model-test.mjs had an if/else whose two arms were byte-identical
except for the endpoint URL. Hoisted the URL into a ternary and kept one
fetch. -48 lines, no behavior change.

Deliberately NOT consolidating the two scripts into a shared module despite
a 24.76% clone rate: each examples/<persona>/ folder is meant to be copied
out whole, its docs use folder-relative commands with no repo-root
dependency, and the parts that would need parameterizing (the 12 prompts,
system prompt, scoring regexes) are the persona itself. jscpd found 0 clones
between the two fetch-data.sh files — those are independently written, not
copy-paste.
- weak-model-test.mjs: the scoring comment said "Anti-pattern penalty (max -1)"
  but the code is Math.min(antiFound.length, 2) -> max -2. README:95 and the
  script's own generated methodology both say -2; the comment was the outlier.
- Drop comments that only restate the line below ("Also check for general
  Karpathy voice markers", "Anti-pattern penalty", "Write results markdown",
  "// Main"). Kept the ones carrying intent, e.g. the scoring rubric.
- steipete: trim the inline "leverage" note to the part that is true; it
  promised a verb/noun distinction the code never implemented.
- check-links.mjs: fix a dangling article ("the markdownlint handles").

Not done: the "# --- N. Title ---" dividers in fetch-data.sh. They mirror the
echo below them but serve a different reader, and they are what makes a
174-line shell script navigable.
check-links.mjs scanned only root-level *.md — five files that contain no
relative links at all. It reported "0 relative link(s) across 5 doc(s)" and
the CI job named "Check relative links" passed unconditionally. Cause: commit
9edda35 moved README/CONTRIBUTING/SECURITY into .github/ and the script's
scope was never updated, so the comment describing what it catches ("a README
pointing at a file that no longer exists") named the exact failure mode it
could no longer see.

Now scans root + .github/ + the folder guides + per-example README/QUICKSTART,
still excluding examples/*/data/ and the persona files (both carry links that
are not ours to keep resolvable). 20 links across 20 docs, green. Verified it
fails correctly by injecting a broken link: exits 1 and names the target.

Also unified SURF_AI_API_KEY -> SURF_API_KEY across fetch-data.sh and
steipete/README.md. pull-x.mjs reads SURF_API_KEY, so following the documented
instructions hit `exit(1)` and section 4 of the pipeline had never run.
- Strip "task brief / task spec / per task requirement" leaks (10 sites).
  These referenced a brief that only ever existed in the prompt of whatever
  agent authored the files. steipete's harness emitted the phrase into its
  generated output, so both the generators (weak-model-test.mjs:286,340) and
  the already-emitted artifact (tests/weak-model-results.md:21,267) are fixed
  — otherwise the next run would put it straight back.

- README trees now match disk: garry-tan documented data/x, data/writing and
  data/yt (none exist; they are created by scripts/ on first run) and listed
  2 of the 6 files in tests/; vivian-balakrishnan documented a data/speeches/
  that does not exist; vitalik-buterin omitted tests/ while linking into it.
  Also corrected garry-tan's tree root label (garrytan/ -> garry-tan/).

- BUILD.md and data/_GUIDE.md had zero inbound references repo-wide. Linked
  both from CONTRIBUTING.md. They are product docs that fell out of the nav,
  not stale files.

- run_weak_model.py: stop catching HTTPError and returning "[ERROR 401: ...]"
  as if it were the model's answer — that wrote a complete-looking results
  file and exited 0, for an artifact published as proof the soul file works.
  The error now propagates and the transcript truncates honestly. Dropped the
  ~/.hermes/.env fallback (a personal-machine path) and the now-unused
  urllib.error import; documented the certifi dependency instead.
Two of the three files the silent-curl bug poisoned are now real data. Fixed
the sources first so a re-run stays correct, then re-fetched:

- data/writing/software-2.0.html: was a 9379-byte GitHub Pages 404. The essay
  is on Medium, not karpathy.github.io — the URL in BLOG_URLS was simply
  wrong. Now 240KB of the real essay ("I sometimes see people refer to neural
  networks as just another tool in your machine learning toolbox", Nov 2017).
  This is what SOUL.md:20 calls "my core thesis" and what weak-model-test.mjs
  scores against, so it was the load-bearing one.
- data/github/karpathy_char-rnn_README.md: was 14 bytes of "404: Not Found".
  That repo ships Readme.md, not README.md. Now the real 12.8KB README. The
  fetch loop now tries README.md/Readme.md/readme.md across master and main
  rather than assuming one spelling.

Verified BLOG_SLUGS and BLOG_URLS still pair 1:1 (13/13) after the URL swap —
they are positionally matched by `set -- $BLOG_URLS`, so a miscount would
silently mislabel every file after it.

Not repaired: data/x/steipete.replies.json is still [] and needs a
SURF_API_KEY to re-pull. Annotated it in the README so it can't be mistaken
for "steipete has no replies" — its sibling openclaw.replies.json has 100.

Swept all of examples/*/data for other empty or error-body files: none.
- .github/README.md: every star count in the frameworks table was stale and
  UNDERSTATED. Verified all 9 repos against the GitHub API: OpenClaw 322k ->
  383k, Nanobot 34.6k -> 46k, ZeroClaw 27.8k -> 32.3k, NanoClaw 24k -> 30.3k,
  PicoClaw 25.3k -> 29.7k, OpenFang 14.9k -> 18k, IronClaw 10.4k -> 12.5k, and
  Hermes Agent 8.7k -> 218k (checked full_name for a redirect; there is none).
  Re-sorted, since the table is ordered by stars.

- garry-tan/weak_model_test.md embedded a "reference implementation" using the
  openai SDK, OPENAI_API_KEY and a --prompts flag. The real run_weak_model.py
  uses urllib + OpenRouter + certifi and has no such flag. After the earlier
  commit corrected the invocation above it, the file contradicted itself.
  Replaced the 40-line fake with a pointer to the actual script.

- karpathy/fetch-data.sh: the transcript cache checked for .vtt files, but only
  the derived .en.txt is committed (0 .vtt in the repo) — so every transcript
  re-downloaded on every run despite the script advertising "Idempotent".
  Now checks the .txt that actually exists.

- karpathy/fetch-data.sh: "YouTube video IDs saved to SOURCES.md" claimed an
  action the script never performs; SOURCES.md is hand-maintained.

- garry-tan/README.md: `claude --skill soul` -> `/soul` to match every other
  doc; dropped the pre-merge "structured to be dropped into" line.

- .markdownlint-cli2.jsonc: dropped the vestigial node_modules ignore (no
  package.json in this repo).
@aaronjmars
aaronjmars merged commit 973a790 into main Jul 21, 2026
2 checks passed
@aaronjmars
aaronjmars deleted the optimize/cleanup branch July 21, 2026 15:00
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