Inspiration
Live coding and interactive gaming streams on Twitch thrive on audience participation, yet "Twitch Plays" style crowd control breaks down when viewers try to co-author real code changes: unstructured chat spam, unsafe arbitrary code execution, and opaque moderator bias make live crowd-patching dangerous. We built patchcrowd (by architect) to turn Twitch chat and Channel Points into a deterministic, cryptographically verifiable live software workbench powered by OpenAI Codex.
What it does
patchcrowd transforms a live Twitch stream into a multi-stage tournament where viewers propose, vote on, and verify real-time code patches synthesized by OpenAI Codex:
- Cryptographic Twitch EventSub Ingestion (
twitch-eventsub-verifier.mjs): Verifies liveTwitch-Eventsub-Message-SignatureHMAC-SHA256 webhooks (channel.chat.messagefor!patch/!votecommands andchannel.channel_points_custom_reward_redemption.addfor boosted proposals) using constant-time digest comparison (crypto.timingSafeEqual), a 10-minute replay window guard, and Message-Id deduplication. - Server-Authoritative Tournament Bracket (
bracket-sync.mjs&reputation-quorum.mjs): Aggregates viewer proposals into a deterministic state machine (COLLECTING_PATCHES -> BRACKET_VOTING -> CODEX_SYNTHESIS -> SANDBOX_VERIFICATION -> ROUND_COMPLETE) with monotonic sequence numbers, single-vote-per-viewer enforcement, and Sybil-resistant bounded reputation weights[0.5, 2.0]. - OpenAI Codex Synthesis & 6-Stage Fail-Closed Sandbox Gate (
codex-sandbox-gate.mjs): Sends the winning crowd prompt to OpenAI Codex with strict JSON Schema output enforcement, then validates the returned patch through a 6-stage fail-closed security gate blocking dangerous tokens (eval,Function,child_process,process.env, filesystem/network escapes, prototype pollution) and restricting edits to an explicit allowlist (game-config.js,physics-rules.js,hud-theme.css). - Tamper-Evident SHA-256 Receipt Chain (
receipt-chain.mjs): Every accepted or refused patch is recorded in an append-only SHA-256 hash-linked ledger (genesis -> round_n) streamed in real time over Server-Sent Events (SSE) to the broadcaster and viewer Daylight workbench (#F8F7F4).
How we built it
- OpenAI Codex CLI & Structured Outputs: Used OpenAI Codex (
0.116.0, clean-room session ID01a1948d-c084-73c1-bec3-8e8e5a3731db) to scaffold, harden, and adversarially test the zero-dependency Node.js ES module architecture (server.mjs,client.mjs,twitch-eventsub-verifier.mjs,bracket-sync.mjs,codex-sandbox-gate.mjs,receipt-chain.mjs,reputation-quorum.mjs,canonical-encoding.mjs,refusal-codes.mjs). - Zero External Dependencies: Built entirely on Node.js built-in
node:http,node:crypto, andnode:test, with a 78-test verification suite (patchcrowd.test.mjsandbrowser-boundary.test.mjs) covering EventSub signature verification, bracket quorum tie-breaking, adversarial Codex prompt injection vectors, and browser security boundaries.
Challenges we ran into
- Untrusted Crowd Prompts -> Code Execution: Viewers on Twitch actively attempt prompt injection (e.g., asking Codex to read environment variables or spawn shells). We solved this by pairing strict OpenAI JSON Schema structured outputs with a two-layer lexical + structural AST/token validator (
validatePatchProposal) that refuses unsafe diffs with deterministic refusal codes (REFUSAL_FORBIDDEN_TOKEN,REFUSAL_TARGET_FILE_NOT_ALLOWED,REFUSAL_DIFF_BUDGET_EXCEEDED) before any code reaches the preview sandbox. - High-Velocity Chat & Replay Attacks: Handling bursts of concurrent
!voteevents without race conditions or forged webhook replays required strict monotonic sequence locking and constant-time HMAC-SHA256 verification.
Accomplishments that we're proud of
- 78/78 Automated Security, Unit, and Browser-Boundary Tests Passing with zero external npm dependencies.
- End-to-End Cryptographic Verifiability: Every round produces a canonical JSON SHA-256 receipt linking the Twitch EventSub message IDs, viewer vote tally, Codex patch diff hash, and sandbox verification verdict.
What we learned
Combining OpenAI Codex's fast structured diff synthesis with deterministic fail-closed sandboxing makes real-time collaborative coding with thousands of live Twitch viewers both safe and genuinely playable.
What's next for patchcrowd
- Native Twitch Extension overlay panel (
video_overlay.html) so viewers can inspect the live SHA-256 receipt chain and diff preview directly inside the Twitch video player. - Multi-round branch tournaments where viewers can fork or revert prior crowd patches across stream sessions.
Built With
- eventsub
- html5
- javascript
- node.js
- openai-codex
- sha-256
- sse
- twitch
Log in or sign up for Devpost to join the conversation.