Search⌘KLights off
Sam Gu

CogPortal

Demo day, before demo day. Cog*Works teams benchmark their capstones on a laptop, then on hidden tests in a sandbox.

MIT BWSI

I built CogPortal from scratch as lead TA for Cog*Works, the pre-college machine learning course at MIT’s Beaver Works Summer Institute. Teams practice locally with a pip-installable CLI, then run their capstones against hidden test labels in a network-blocked Modal evaluation sandbox. A portal on Cloudflare Workers shows each team’s chosen official result on a live leaderboard, and a Discord bot posts the results. It scored all 15 team projects across the course’s three capstones.

Four surfaces, one run

A sample run across CogPortal’s four surfaces, with the portal’s and the bot’s own words on the repo’s demo fixture. The desk and devices are drawn for this page, the count in the finding is made up, and no score is shown, as the portal shows none.

Four surfaces, one run

A team meets CogPortal in four places. Local practice uses the CLI, a hosted run can start from the portal or from Discord, and Modal does the evaluation.

  • The cogworks CLI, where they check and test their code on their own machine.
  • The Modal evaluation sandbox, where a pushed commit runs with the inputs but no secrets and no network.
  • The portal, whose run page leads with what the run shows, in the course’s own words, before any trace or log.
  • CogBot on Discord, whose private /cog command shows a team’s runs and official attempts without leaving the server.

Where it came from

On July 24, an instructor gave up a lunch break to build a demo-day benchmark by hand. He pulled captions from COCO at three levels of difficulty, randomized which ones each team got so nobody could tune to them, and ran every team live on the projector. Half of it failed, and the room treated that as normal. It was a held-out evaluation done right, and it existed only because one person improvised it. CogPortal builds that hour into software.

Three levels of trust

  • Local practice. cogworks check works offline after install, and test and run work offline once the public data and models they fetch on first use are cached. None of them needs an account. cogworks sync uploads one report you pick (the latest by default) with the weight files that run used, and the portal marks the result self-reported.
  • Hosted practice. The same code runs in a Modal evaluation sandbox that gets inputs but no secrets and no network. The hidden labels stay with a trusted controller outside it.
  • Official evaluation. An official run has to reuse the exact artifact from a successful practice run at the same commit, and attempts are limited.

The CLI covers the four benchmarks written for the course: song identification, face recognition, face clustering and caption-to-image search.

How each surface was built

The CLI

cogworks is a Python 3.8+ package with one command. It runs a team’s submission.py when the repository has one at its root. Otherwise it finds the team’s functions however they’re named, split or wrapped in classes, by calling them in sequence and keeping only a chain that passes the benchmark’s own test, such as naming an enrolled song back from a two-second clip. A recorded run cleared the 13-repository corpus in 36 seconds. Before profiling, one repository alone took 272 seconds.

The discovery step’s time, before and after profilingA time line from 0 to 300 seconds. Before profiling, one repository alone took 272 seconds. A recorded run now clears all 13 repositories in 36.060120180240300 sone repo before, 272 sall 13 now, 36 sThe discovery step’s time, before and after profilingA time line from 0 to 300 seconds. Before profiling, one repository alone took 272 seconds. A recorded run now clears all 13 repositories in 36.060120180240300 sone repo before, 272 sall 13 now, 36 s
The discovery step’s time from CogPortal’s recorded demo run. Before profiling, one repository alone took 272 seconds, and the recorded run cleared all 13 in 36.

Four of those repositories had needed an adapter written by an instructor, and discovery reproduced two of those adapters’ scores to four decimal places. The published package, 0.1.0 on TestPyPI, predates discovery.

The 13 repositories, the four that had needed an adapter, and the two discovery matchedA strip of 13 cells, one per repository, grouped by outcome. Four cells are outlined: those repositories had needed an adapter written by an instructor. Two of the four are filled: discovery reproduced those adapters’ scores to four decimal places.needed an adaptermatched to 4 decimals13 repositoriesThe 13 repositories, the four that had needed an adapter, and the two discovery matchedA strip of 13 cells, one per repository, grouped by outcome. Four cells are outlined: those repositories had needed an adapter written by an instructor. Two of the four are filled: discovery reproduced those adapters’ scores to four decimal places.needed an adaptermatched to 4 decimals13 repositories
The 13 repositories in the discovery demo, grouped by outcome rather than listed in order. Four had needed an adapter written by an instructor, and discovery matched two of those adapters’ scores to four decimal places.

The sandbox

A trusted controller runs two sandboxes: one that prepares a run, with an allowlisted network, and one that evaluates it, with no network and no secrets. The controller keeps the hidden labels, scores the predictions and signs each event.

The same code has to score the same everywhere. Song identification scored differently on macOS ARM (Python 3.11, NumPy 2.4) and on Linux x86-64 (Python 3.8.20, NumPy 1.24.4), until the audio path used exact operations and checked audio hashes. The hosted score is now 0.5375 over 282 cases.

Song identification on two machines, before and after the fixTwo machines side by side: macOS ARM with Python 3.11 and NumPy 2.4, and Linux x86-64 with Python 3.8.20 and NumPy 1.24.4. Their audio differed. A bracket joins them below: after exact operations and audio hashes, they match, and the hosted score is 0.5375 over 282 cases.macOS ARMPython 3.11NumPy 2.4Linux x86-64Python 3.8.20NumPy 1.24.4differsexact operations, audio hashesmatcheshosted score 0.5375 over 282 casesSong identification on two machines, before and after the fixTwo machines side by side: macOS ARM with Python 3.11 and NumPy 2.4, and Linux x86-64 with Python 3.8.20 and NumPy 1.24.4. Their audio differed. A bracket joins them below: after exact operations and audio hashes, they match, and the hosted score is 0.5375 over 282 cases.macOS ARMPython 3.11NumPy 2.4Linux x86-64Python 3.8.20NumPy 1.24.4differsexact operations,audio hashesmatcheshosted score 0.5375 over 282 cases
The two machines whose audio scored differently in CogPortal’s corpus tests. Song identification scored differently on them until the audio path used exact operations and checked audio hashes, and the hosted score is now 0.5375 over 282 cases.

One team’s score moved from 0.8188 to 0.8335 across three values of PYTHONHASHSEED, so the runner pins the seed.

One team’s score across three hash seedsA score axis from 0.81 to 0.84. A bar spans the scores one team got across three values of PYTHONHASHSEED, from 0.8188 to 0.8335. The runner now pins the seed.0.810.820.830.840.81880.8335three seedsseed now pinnedOne team’s score across three hash seedsA score axis from 0.81 to 0.84. A bar spans the scores one team got across three values of PYTHONHASHSEED, from 0.8188 to 0.8335. The runner now pins the seed.0.810.820.830.840.81880.8335three seedsseed now pinned
One team’s score across three values of PYTHONHASHSEED, from the runner’s code. Only the lowest and highest scores are known, so the bar shows just its two ends, and the runner now pins the seed.

The order of the cases could leak the answers. Trying 36 orderings of a case with two identities could recover its hidden labels, so each case now gets a permutation seed derived with an HMAC, stable across submissions and never shown.

36 orderings that could recover a case’s hidden labels, and the seed that stops themA grid of 36 small cells, one per ordering of a case with two identities. Trying them all could recover the case’s hidden labels. An arrow leads to a lock: each case now gets a permutation seed derived with an HMAC, stable across submissions and hidden.36 orderingscould recoverthe hidden labelsan HMAC-derived seedper casestable and hidden36 orderings that could recover a case’s hidden labels, and the seed that stops themA grid of 36 small cells, one per ordering of a case with two identities. Trying them all could recover the case’s hidden labels. An arrow leads to a lock: each case now gets a permutation seed derived with an HMAC, stable across submissions and hidden.36 orderingscould recoverthe hidden labelsan HMAC-derived seedper casestable and hidden
Trying 36 orderings of one case with two identities could recover its hidden labels. Each case now gets a permutation seed derived with an HMAC, stable across submissions and never shown.

When a machine was preempted, KeyboardInterrupt slipped past an except Exception and left a claimed run with no outcome. The runner now settles interrupted runs, and replay tests hold it to that.

The portal

The portal is React and TypeScript on a Hono Worker, with D1 and a run queue. Each team gets 10 completed practice runs and 3 completed official runs per benchmark and version. Failed, cancelled and refunded runs don’t count, and a run is admitted inside one transaction.

The runs each team gets per benchmark and versionA ledger of completed runs per team, benchmark and version: a row of 10 practice runs and a row of 3 official runs. Two more cells are crossed out: failed runs, which don’t count.completed runs per team, benchmark and version10 practice runs3 official runsfailed, not countedThe runs each team gets per benchmark and versionA ledger of completed runs per team, benchmark and version: a row of 10 practice runs and a row of 3 official runs. Two more cells are crossed out: failed runs, which don’t count.completed runs per team,benchmark and version10 practice runs3 official runsfailed, not counted
The portal’s run quota for one team on one benchmark and version, from its run accounting. Only completed runs fill a cell, since failed, cancelled and refunded runs don’t count, and a run is admitted inside one transaction.

CogBot

CogBot is a Worker that checks Discord’s signature on every request and answers privately. It reaches the portal through a typed service binding, never the database. The portal keeps each run’s message current through a Durable Object that updates it every 2 seconds and waits as long as Retry-After says when Discord answers 429.

How a run’s message in Discord stays currentA sequence: Discord, then the bot, then the portal, then a Durable Object, then the run’s message. A loop beside the Durable Object updates the message every 2 seconds. When Discord answers 429, it waits as long as Retry-After says.DiscordbotportalDurable Objectmessageupdates every 2 s429: wait for Retry-AfterHow a run’s message in Discord stays currentA sequence: Discord, then the bot, then the portal, then a Durable Object, then the run’s message. A loop beside the Durable Object updates the message every 2 seconds. When Discord answers 429, it waits as long as Retry-After says.DiscordbotportalDurable Objectmessageupdatesevery 2 s429: wait for Retry-After
How a Discord request becomes a run’s live message. A Durable Object updates the message every 2 seconds, and when Discord answers 429 it waits as long as Retry-After says.

Rules the build enforces

Two rules are tests, not guidelines. A benchmark that explains its metrics in the course’s own vocabulary has to explain every metric it labels, or the build fails; older benchmarks without explanations are skipped. And the signals the portal derives from a team’s process can’t carry a per-person number, because a seventeen-year-old reads any per-person number as a grade.

I test changes on a separate staging beta with its own Modal app. I’m now working with BWSI to extend CogPortal to the institute’s other courses, starting with a connector for the Edly LMS.

Built with
Python, React, Cloudflare Workers, Modal

Contact

sgu07966@gmail.com

Sam Gu’s card. Computer science, UT Austin. Austin, TX. kgu.one.

Built from a commit to kgu.one on 2 November 2026.

Sam is in Austin (Central Time).