codex_manager / index.html
ernanhughes's picture
Update index.html
14fe706 verified
Raw
History Blame Contribute Delete
130 kB
<!DOCTYPE html>
<html class="no-js" lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Codex Manager: Building a Prompt-State Runtime for Hackathon-Grade Code Optimization - Programmer.ie: Modern AI programming</title>
<script>(function(d,e){d[e]=d[e].replace("no-js","js");})(document.documentElement,"className");</script>
<meta name="description" content="">
<meta property="og:title" content="Codex Manager: Building a Prompt-State Runtime for Hackathon-Grade Code Optimization">
<meta property="og:description" content="TL;DR Codex Manager uses AI to generate code as an artifact, then tests that artifact, diagnoses what happened, and repairs the prompt state that produced it. The code is not the thing being optimized directly. The prompt state is.
Summary Humanity’s Last Hackathon framed the challenge as a test of context, not code: the task was hard enough that the real question was not whether someone could hand-write one clever kernel, but whether they could build a system that used AI effectively under changing constraints.">
<meta property="og:locale" content="en_us">
<meta property="og:type" content="article">
<meta property="article:section" content="post">
<meta property="article:published_time" content="2026-05-16T20:15:59+01:00">
<meta property="article:modified_time" content="2026-05-16T20:15:59+01:00">
<meta property="article:tag" content="AI Coding">
<meta property="article:tag" content="Prompt Engineering">
<meta property="article:tag" content="Agentic Systems">
<meta property="article:tag" content="Software Architecture">
<meta property="article:tag" content="Developer Tools">
<meta property="article:tag" content="Hackathon">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Codex Manager: Building a Prompt-State Runtime for Hackathon-Grade Code Optimization">
<meta name="twitter:description" content="TL;DR Codex Manager uses AI to generate code as an artifact, then tests that artifact, diagnoses what happened, and repairs the prompt state that produced it. The code is not the thing being optimized directly. The prompt state is.
Summary Humanity’s Last Hackathon framed the challenge as a test of context, not code: the task was hard enough that the real question was not whether someone could hand-write one clever kernel, but whether they could build a system that used AI effectively under changing constraints.">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="dns-prefetch" href="//fonts.googleapis.com">
<link rel="dns-prefetch" href="//fonts.gstatic.com">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:400,400i,700">
<link rel="stylesheet" href="/css/style.css">
<link rel="shortcut icon" href="/favicon.ico">
<link rel="icon" href="/favicon.png" type="image/x-icon" />
</head>
<body class="body">
<div class="container container--outer">
<header class="header">
<div class="container header__container">
<script>
window.MathJax = {
tex: {
inlineMath: [['\\(', '\\)']],
displayMath: [['$$','$$'], ['\\[','\\]']],
processEscapes: true,
tags: 'ams'
},
options: {
skipHtmlTags: ['script','noscript','style','textarea','pre','code']
}
};
</script>
<script async id="mathjax-script" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
<div class="logo">
<a class="logo__link" href="/" title="Programmer.ie: Modern AI programming" rel="home">
<div class="logo__item logo__text">
</div>
</a>
</div>
<nav class="menu">
<button class="menu__btn" aria-haspopup="true" aria-expanded="false" tabindex="0">
<span class="menu__btn-title" tabindex="-1">Menu</span>
</button>
<ul class="menu__list">
<li class="menu__item">
<a class="menu__link" href="/">
<span class="menu__text">Home</span>
</a>
</li>
<li class="menu__item">
<a class="menu__link" href="/categories/ai/">
<span class="menu__text">AI</span>
</a>
</li>
<li class="menu__item">
<a class="menu__link" href="/categories/finance/">
<span class="menu__text">Finance</span>
</a>
</li>
<li class="menu__item">
<a class="menu__link" href="/categories/programming/">
<span class="menu__text">Programming</span>
</a>
</li>
<li class="menu__item">
<a class="menu__link" href="/lists/">
<span class="menu__text">Lists</span>
</a>
</li>
<li class="menu__item">
<a class="menu__link" href="/about/">
<span class="menu__text">About</span>
</a>
</li>
</ul>
</nav>
</div>
</header>
<div class="wrapper flex">
<div class="primary">
<main class="main" role="main">
<article class="post">
<header class="post__header">
<h1 class="post__title">Codex Manager: Building a Prompt-State Runtime for Hackathon-Grade Code Optimization</h1>
<div class="post__meta meta"><div class="meta__item-categories meta__item"><svg class="meta__icon icon icon-category" width="16" height="16" viewBox="0 0 16 16"><path d="m7 2 1 2h8v11H0V2z"/></svg><span class="meta__text"><a class="meta__link" href="/categories/ai/" rel="category">AI</a>, <a class="meta__link" href="/categories/programming/" rel="category">Programming</a>
</span>
</div>
<div class="meta__item-datetime meta__item">
<svg class="meta__icon icon icon-time" width="16" height="14" viewBox="0 0 30 28"><path d="M15 0a14 14 0 1 1 0 28 1 1 0 0 1 0-28m0 3a3 3 0 1 0 0 22 3 3 0 0 0 0-22m1 4h-2v8.4l6.8 4.4L22 18l-6-3.8z"/></svg><time class="meta__text" datetime="2026-05-16T20:15:59&#43;01:00">May 16, 2026</time></div></div>
</header>
<figure class="post__thumbnail thumbnail">
<img class="thumbnail__image" src="/img/codex.png" alt="Codex Manager: Building a Prompt-State Runtime for Hackathon-Grade Code Optimization">
</figure>
<div class="post__toc toc">
<div class="toc__title">Page content</div>
<div class="toc__menu">
<nav id="TableOfContents">
<ul>
<li><a href="#tldr">TL;DR</a></li>
<li><a href="#summary">Summary</a></li>
<li><a href="#what-is-codex-manager">What Is Codex Manager?</a></li>
<li><a href="#the-core-idea-promptstate-not-code">The Core Idea: PromptState, Not Code</a></li>
<li><a href="#the-loop-from-candidate-to-evidence">The Loop: From Candidate to Evidence</a></li>
<li><a href="#diagnosis-and-repair-turning-failure-into-the-next-prompt">Diagnosis and Repair: Turning Failure into the Next Prompt</a></li>
<li><a href="#the-staircase-we-built">The Staircase We Built</a></li>
<li><a href="#cold-example-1-a-portable-vector_add-task-pack">Cold Example 1: A Portable <code>vector_add</code> Task Pack</a></li>
<li><a href="#cold-example-2-command-driven-evaluation">Cold Example 2: Command-Driven Evaluation</a></li>
<li><a href="#cold-example-3-one-command-pipeline">Cold Example 3: One Command Pipeline</a></li>
<li><a href="#the-artifact-trail-evidence-has-structure">The Artifact Trail: Evidence Has Structure</a></li>
<li><a href="#make-the-ai-work-harder">Make the AI Work Harder</a></li>
<li><a href="#what-comes-next-applying-the-manager">What Comes Next: Applying the Manager</a></li>
<li><a href="#references">References</a></li>
<li><a href="#appendix-a-the-codex-manager-loop-in-pseudo-code">Appendix A: The Codex Manager Loop in Pseudo-Code</a>
<ul>
<li><a href="#the-candidate-is-not-trusted">The Candidate Is Not Trusted</a></li>
<li><a href="#the-profile-turns-a-candidate-into-evidence">The Profile Turns a Candidate into Evidence</a></li>
<li><a href="#diagnosis-interprets-evidence">Diagnosis Interprets Evidence</a></li>
<li><a href="#repair-mutates-promptstate">Repair Mutates PromptState</a></li>
<li><a href="#promptstate-carries-the-loop-forward">PromptState Carries the Loop Forward</a></li>
<li><a href="#artifacts-are-written-at-every-step">Artifacts Are Written at Every Step</a></li>
</ul>
</li>
<li><a href="#glossary">Glossary</a></li>
</ul>
</nav>
</div>
</div><div class="content post__content clearfix">
<h2 id="tldr">TL;DR</h2>
<p>Codex Manager uses AI to generate code as an artifact, then tests that artifact, diagnoses what happened, and repairs the prompt state that produced it. The code is not the thing being optimized directly. The prompt state is.</p>
<h2 id="summary">Summary</h2>
<p><a href="https://huggingface.co/humanitys-last-hackathon?utm_source=chatgpt.com">Humanity’s Last Hackathon</a> framed the challenge as a test of <strong>context, not code</strong>: the task was hard enough that the real question was not whether someone could hand-write one clever kernel, but whether they could build a system that used AI effectively under changing constraints.</p>
<p><strong>Codex Manager</strong> is our attempt at that idea: a prompt-state runtime that manages Codex through candidate generation, isolated execution, diagnosis, repair, and verified promotion.</p>
<h2 id="what-is-codex-manager">What Is Codex Manager?</h2>
<p>Codex Manager starts from one simple claim:</p>
<blockquote>
<p><strong>Codex Manager optimizes PromptState, not code. Candidate code is evidence.</strong></p>
</blockquote>
<p>Instead of treating generated code as the answer, the system treats it as a proposal that must survive a controlled loop.</p>
<p>Codex proposes a candidate diff. The manager applies it in an isolated workspace. Build, correctness, and benchmark gates decide whether the candidate is real. Failed attempts become diagnoses. Diagnoses become prompt deltas. Prompt deltas update the next <code>PromptState</code>. Only candidates that pass correctness and improve the benchmark are allowed to survive.</p>
<p>That shift from optimizing code directly to optimizing the state around code generation shaped the entire architecture.</p>
<p>Over the course of the build, Codex Manager grew from a small prompt-repair loop into a complete hackathon-style runtime:</p>
<ul>
<li>task packs</li>
<li>shadow execution</li>
<li>command benchmarks</li>
<li>candidate executor registries</li>
<li>reproducible run bundles</li>
<li>submission packaging</li>
<li>platform exports</li>
<li>a full pipeline orchestrator</li>
<li>a CLI that runs the workflow from the terminal</li>
</ul>
<p>The result is not just a tool for one benchmark. It is a pattern for agentic coding systems:</p>
<pre class="mermaid">
flowchart LR
%% Start of the loop
PS[&#34;🧠 PromptState&lt;br/&gt;(task, context, lessons, warnings, banned)&#34;]
%% Codex generation
PS --&gt;|&#34;generate()&#34;| C[&#34;🤖 Codex&lt;br/&gt;(candidate generator)&#34;]
C --&gt;|&#34;unified diff&#34;| AR[&#34;🔬 AttemptResult&lt;br/&gt;(applied, compiled, correct, speedup)&#34;]
%% Evidence gates
AR --&gt;|&#34;fails gate&#34;| D[&#34;🩺 AttemptDiagnosis&lt;br/&gt;(what failed &amp; why)&#34;]
AR --&gt;|&#34;passes &amp; improves&#34;| PROMO[&#34;✅ Promote Candidate&lt;br/&gt;(verified improvement)&#34;]
%% Repair &amp; feedback
D --&gt;|&#34;diagnosis → lesson&#34;| PD[&#34;🔄 PromptDelta&lt;br/&gt;(new constraints, lessons, banned moves)&#34;]
PD --&gt;|&#34;apply delta&#34;| PS
%% Styling
classDef state fill:#e0f0ff,stroke:#3a6ea5,stroke-width:2px,color:#1a2b3c
classDef evidence fill:#fff7e0,stroke:#d9a34a,stroke-width:2px,color:#4a3a1a
classDef gate fill:#e6ffe6,stroke:#4a9d4a,stroke-width:2px,color:#1a3c1a
classDef promote fill:#e6ffe6,stroke:#4a9d4a,stroke-width:3px,color:#0a3d0a,font-weight:bold
class PS state
class C evidence
class AR evidence
class D gate
class PROMO promote
class PD state
</pre>
<p>The model generates. The manager evaluates. The prompt state evolves. The artifacts prove what happened.</p>
<p>This post walks through that system from the first design decision to the final command-line pipeline, using a concrete <code>vector_add</code> example to show how the pieces fit together.</p>
<hr>
<h2 id="the-core-idea-promptstate-not-code">The Core Idea: PromptState, Not Code</h2>
<p>Once we stopped treating the hackathon as a code-writing contest, the design became much clearer.</p>
<p>The thing to optimize was not the kernel.</p>
<p>The thing to optimize was the <strong>state around Codex</strong>.</p>
<p>We called that state <code>PromptState</code>.</p>
<blockquote>
<p>PromptState is the evolving memory of the run: the constraints, lessons, warnings, and contracts that shape the next candidate.</p>
</blockquote>
<p>Most code-generation systems treat the prompt as temporary. A prompt is assembled, sent to the model, and discarded. If the result fails, the next prompt is usually improvised: “try again,” “fix the bug,” “make it faster,” “preserve correctness this time.”</p>
<p>That works for small interactions. It does not work as an engineering loop.</p>
<p>A serious manager needs a structured object that says:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-text" data-lang="text"><span style="display:flex;"><span>Here is what the model currently knows.
</span></span><span style="display:flex;"><span>Here are the mistakes it has already made.
</span></span><span style="display:flex;"><span>Here are the moves it is no longer allowed to make.
</span></span><span style="display:flex;"><span>Here are the patterns it should preserve.
</span></span><span style="display:flex;"><span>Here is the exact output contract it must obey.
</span></span></code></pre></div><p>Codex Manager makes that explicit.</p>
<p>A <code>PromptState</code> is not just a prompt string. It is the working memory of the run.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#66d9ef">class</span> <span style="color:#a6e22e">PromptStateDTO</span>(BaseModel):
</span></span><span style="display:flex;"><span> run_id: str
</span></span><span style="display:flex;"><span> task_id: str
</span></span><span style="display:flex;"><span> attempt_id: str
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> context_pack: str
</span></span><span style="display:flex;"><span> system_prompt: str
</span></span><span style="display:flex;"><span> user_prompt: str
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> prior_lessons: list[str] <span style="color:#f92672">=</span> Field(default_factory<span style="color:#f92672">=</span>list)
</span></span><span style="display:flex;"><span> failure_warnings: list[str] <span style="color:#f92672">=</span> Field(default_factory<span style="color:#f92672">=</span>list)
</span></span><span style="display:flex;"><span> success_patterns: list[str] <span style="color:#f92672">=</span> Field(default_factory<span style="color:#f92672">=</span>list)
</span></span><span style="display:flex;"><span> banned_moves: list[str] <span style="color:#f92672">=</span> Field(default_factory<span style="color:#f92672">=</span>list)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> output_contract: str
</span></span></code></pre></div><p>This is the real optimization surface.</p>
<p>The code changes every attempt, but the state accumulates.</p>
<p>A candidate might fail because it returned prose instead of a diff. Another might apply cleanly but break correctness. Another might pass correctness and regress performance. Each of those outcomes teaches the manager something different. The next prompt should not merely be louder or longer. It should be <strong>more informed</strong>.</p>
<p>That is what <code>PromptState</code> gives us.</p>
<p>The loop becomes:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-text" data-lang="text"><span style="display:flex;"><span>PromptState
</span></span><span style="display:flex;"><span>→ candidate generated by Codex
</span></span><span style="display:flex;"><span>→ candidate evaluated as evidence
</span></span><span style="display:flex;"><span>→ failure or success diagnosed
</span></span><span style="display:flex;"><span>→ prompt delta produced
</span></span><span style="display:flex;"><span>→ next PromptState
</span></span></code></pre></div><p>Codex is still doing valuable work. It proposes code. But the manager decides how the next proposal should be shaped.</p>
<p>That is the central inversion:</p>
<blockquote>
<p>Codex generates candidates. Codex Manager evolves the conditions under which candidates are generated.</p>
</blockquote>
<p>The candidate code is no longer treated as the final answer. It is treated as an experiment.</p>
<p>Did it apply cleanly?</p>
<p>Did it build?</p>
<p>Did it preserve correctness?</p>
<p>Did it improve the benchmark?</p>
<p>Did it violate the output contract?</p>
<p>Did it touch files it was not allowed to touch?</p>
<p>The answers become structured evidence. That evidence becomes a diagnosis. The diagnosis becomes a prompt delta. The prompt delta becomes the next <code>PromptState</code>.</p>
<p>For example, if a candidate weakens boundary behavior, the manager does not simply say:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-text" data-lang="text"><span style="display:flex;"><span>Try again.
</span></span></code></pre></div><p>It updates the next prompt with something specific:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-text" data-lang="text"><span style="display:flex;"><span>Previous attempt likely failed because boundary semantics were weakened.
</span></span><span style="display:flex;"><span>Preserve bounds checks and mismatched-length behavior.
</span></span><span style="display:flex;"><span>Do not assume aligned input sizes.
</span></span><span style="display:flex;"><span>Return one valid unified diff against the target file only.
</span></span></code></pre></div><p>If a candidate passes correctness but slows the benchmark, the next prompt changes differently:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-text" data-lang="text"><span style="display:flex;"><span>The previous candidate was correct but slower.
</span></span><span style="display:flex;"><span>Avoid extra branching, allocations, sleeps, or unnecessary memory traffic.
</span></span><span style="display:flex;"><span>Target the measured hotspot directly.
</span></span><span style="display:flex;"><span>Preserve the successful correctness structure.
</span></span></code></pre></div><p>This gives the run a kind of external learning.</p>
<p>The model’s weights do not change. Codex does not become smarter inside the session. But the <strong>context around Codex</strong> becomes more precise, more constrained, and more informed by evidence.</p>
<p>That is why the distinction matters.</p>
<p>A normal agent loop says:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-text" data-lang="text"><span style="display:flex;"><span>generate code
</span></span><span style="display:flex;"><span>test code
</span></span><span style="display:flex;"><span>retry
</span></span></code></pre></div><p>Codex Manager says:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-text" data-lang="text"><span style="display:flex;"><span>generate candidate
</span></span><span style="display:flex;"><span>test candidate
</span></span><span style="display:flex;"><span>diagnose evidence
</span></span><span style="display:flex;"><span>repair PromptState
</span></span><span style="display:flex;"><span>generate under improved constraints
</span></span></code></pre></div><p>The benchmark still matters. The code still matters. But the thing being improved across attempts is the state that shapes the next candidate.</p>
<p>Below is the full prompt-state lifecycle:</p>
<pre class="mermaid">
flowchart TD
A[&#34;🗂️ Task Pack&lt;br/&gt;goal, source, tests, benchmark, constraints&#34;] --&gt; B[&#34;🧠 PromptState&lt;br/&gt;context, lessons, warnings, banned moves, output contract&#34;]
B --&gt; C[&#34;🤖 Codex&lt;br/&gt;candidate generator&#34;]
C --&gt; D[&#34;📝 Candidate Diff&lt;br/&gt;proposed code change&#34;]
D --&gt; E[&#34;🛡️ Isolated Workspace&lt;br/&gt;apply patch safely&#34;]
E --&gt; F{&#34;🧪 Build + Correctness&lt;br/&gt;passes?&#34;}
F -- No --&gt; G[&#34;🔬 AttemptResult&lt;br/&gt;failure evidence&#34;]
F -- Yes --&gt; H{&#34;📊 Benchmark&lt;br/&gt;improves?&#34;}
H -- No --&gt; G
H -- Yes --&gt; I[&#34;✅ Promote Candidate&lt;br/&gt;verified improvement&#34;]
G --&gt; J[&#34;🩺 AttemptDiagnosis&lt;br/&gt;what failed and why&#34;]
J --&gt; K[&#34;🔄 PromptDelta&lt;br/&gt;new constraints, lessons, banned moves&#34;]
K --&gt; B
I --&gt; L[&#34;🗃️ Run Artifacts&lt;br/&gt;PROMPTS.log, reports, bundle, submission&#34;]
classDef config fill:#f0f0ff,stroke:#6a6a9a,stroke-width:2px,color:#1a1a3c
classDef state fill:#e0f0ff,stroke:#3a6ea5,stroke-width:2px,color:#1a2b3c
classDef evidence fill:#fff7e0,stroke:#d9a34a,stroke-width:2px,color:#4a3a1a
classDef gate fill:#e6ffe6,stroke:#4a9d4a,stroke-width:2px,color:#1a3c1a
class A,L config
class B,K state
class C,D,G,J evidence
class E,F,H,I gate
</pre>
<p>Codex does not learn inside the run.</p>
<p>The manager learns externally by turning execution evidence into prompt-state updates.</p>
<p>That is the core idea. The model generates. The harness verifies. The manager updates the state. The artifacts prove the path.</p>
<hr>
<h2 id="the-loop-from-candidate-to-evidence">The Loop: From Candidate to Evidence</h2>
<p>Once <code>PromptState</code> became the thing we were optimizing, the next question was obvious:</p>
<blockquote>
<p>What counts as evidence?</p>
</blockquote>
<p>A generated candidate is not evidence by itself. It is only a proposal.</p>
<p>Codex can return something that looks plausible, follows the shape of the prompt, and even compiles in your head. That does not mean it is correct. It does not mean it is safe. It does not mean it is faster. It does not even mean it is a valid patch.</p>
<p>So the manager has to turn every proposal into a structured result.</p>
<p>That is the job of <code>AttemptResult</code>.</p>
<p>In Codex Manager, an attempt is not “whatever the model said.” An attempt is what remains after the candidate has been tested by the system.</p>
<p>A simplified version looks like this:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#66d9ef">class</span> <span style="color:#a6e22e">AttemptResultDTO</span>(BaseModel):
</span></span><span style="display:flex;"><span> run_id: str
</span></span><span style="display:flex;"><span> task_id: str
</span></span><span style="display:flex;"><span> attempt_id: str
</span></span><span style="display:flex;"><span> prompt_hash: str
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> candidate_text: str <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;&#34;</span>
</span></span><span style="display:flex;"><span> patch_text: str <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;&#34;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> applied: bool <span style="color:#f92672">=</span> <span style="color:#66d9ef">False</span>
</span></span><span style="display:flex;"><span> compiled: bool <span style="color:#f92672">=</span> <span style="color:#66d9ef">False</span>
</span></span><span style="display:flex;"><span> correctness_passed: bool <span style="color:#f92672">=</span> <span style="color:#66d9ef">False</span>
</span></span><span style="display:flex;"><span> benchmark_passed: bool <span style="color:#f92672">=</span> <span style="color:#66d9ef">False</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> baseline_ms: float <span style="color:#f92672">|</span> <span style="color:#66d9ef">None</span> <span style="color:#f92672">=</span> <span style="color:#66d9ef">None</span>
</span></span><span style="display:flex;"><span> median_ms: float <span style="color:#f92672">|</span> <span style="color:#66d9ef">None</span> <span style="color:#f92672">=</span> <span style="color:#66d9ef">None</span>
</span></span><span style="display:flex;"><span> speedup: float <span style="color:#f92672">|</span> <span style="color:#66d9ef">None</span> <span style="color:#f92672">=</span> <span style="color:#66d9ef">None</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> failure_reason: str <span style="color:#f92672">|</span> <span style="color:#66d9ef">None</span> <span style="color:#f92672">=</span> <span style="color:#66d9ef">None</span>
</span></span><span style="display:flex;"><span> raw_test_output: str <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;&#34;</span>
</span></span><span style="display:flex;"><span> raw_benchmark_output: str <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;&#34;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> metadata: dict <span style="color:#f92672">=</span> Field(default_factory<span style="color:#f92672">=</span>dict)
</span></span></code></pre></div><p>This object is how the system prevents hallucinated promotion.</p>
<p>A candidate is not “good” because it sounds good. It is not good because the model says it is optimized. It is not good because the diff looks clever.</p>
<p>It is good only if the evidence says it survived the gates.</p>
<p>An attempt begins when Codex returns a candidate, usually as a unified diff. The manager does not apply that diff to the real source tree. It creates an isolated workspace, copies the task files into it, and applies the patch there.</p>
<p>The flow is deliberately strict:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-text" data-lang="text"><span style="display:flex;"><span>candidate diff
</span></span><span style="display:flex;"><span>→ isolated workspace
</span></span><span style="display:flex;"><span>→ safe patch application
</span></span><span style="display:flex;"><span>→ build gate
</span></span><span style="display:flex;"><span>→ correctness gate
</span></span><span style="display:flex;"><span>→ benchmark gate
</span></span><span style="display:flex;"><span>→ AttemptResult
</span></span></code></pre></div><p>Each gate answers one question:</p>
<ul>
<li><strong>Patch gate:</strong> Did the candidate apply cleanly, and did it only touch allowed files?</li>
<li><strong>Build gate:</strong> Does the modified target still compile or pass the syntax/build step?</li>
<li><strong>Correctness gate:</strong> Does the candidate preserve the required behavior?</li>
<li><strong>Benchmark gate:</strong> If correctness passed, did performance improve?</li>
</ul>
<p>That “if correctness passed” matters.</p>
<p>A faster wrong answer is not an optimization. It is a bug with good timing.</p>
<p>So the benchmark is blocked unless correctness succeeds.</p>
<p>That rule became one of the central design constraints:</p>
<blockquote>
<p><strong>No benchmark result counts unless correctness passes.</strong></p>
</blockquote>
<p>In practice, this prevents the manager from rewarding the most common failure mode in AI-generated optimization: removing necessary logic, weakening checks, changing edge-case behavior, or altering semantics in exchange for speed.</p>
<p>For example, in the <code>vector_add</code> task, the baseline implementation preserves Python <code>zip</code> semantics:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#66d9ef">def</span> <span style="color:#a6e22e">vector_add</span>(a, b):
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">return</span> [x <span style="color:#f92672">+</span> y <span style="color:#66d9ef">for</span> x, y <span style="color:#f92672">in</span> zip(a, b)]
</span></span></code></pre></div><p>A candidate might try to rewrite it as:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#66d9ef">def</span> <span style="color:#a6e22e">vector_add</span>(a, b):
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">return</span> [a[i] <span style="color:#f92672">+</span> b[i] <span style="color:#66d9ef">for</span> i <span style="color:#f92672">in</span> range(len(a))]
</span></span></code></pre></div><p>That looks reasonable for equal-length arrays. It may even appear faster in a narrow benchmark. But it breaks mismatched-length behavior:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span>vector_add([<span style="color:#ae81ff">1</span>, <span style="color:#ae81ff">2</span>, <span style="color:#ae81ff">3</span>], [<span style="color:#ae81ff">10</span>, <span style="color:#ae81ff">20</span>])
</span></span></code></pre></div><p>The correct result should preserve <code>zip</code> behavior:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span>[<span style="color:#ae81ff">11</span>, <span style="color:#ae81ff">22</span>]
</span></span></code></pre></div><p>The rewritten version can index past the shorter list and fail.</p>
<p>That failure becomes structured evidence:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-json" data-lang="json"><span style="display:flex;"><span>{
</span></span><span style="display:flex;"><span> <span style="color:#f92672">&#34;attempt_id&#34;</span>: <span style="color:#e6db74">&#34;attempt_001&#34;</span>,
</span></span><span style="display:flex;"><span> <span style="color:#f92672">&#34;applied&#34;</span>: <span style="color:#66d9ef">true</span>,
</span></span><span style="display:flex;"><span> <span style="color:#f92672">&#34;compiled&#34;</span>: <span style="color:#66d9ef">true</span>,
</span></span><span style="display:flex;"><span> <span style="color:#f92672">&#34;correctness_passed&#34;</span>: <span style="color:#66d9ef">false</span>,
</span></span><span style="display:flex;"><span> <span style="color:#f92672">&#34;benchmark_passed&#34;</span>: <span style="color:#66d9ef">false</span>,
</span></span><span style="display:flex;"><span> <span style="color:#f92672">&#34;failure_reason&#34;</span>: <span style="color:#e6db74">&#34;correctness_failed&#34;</span>,
</span></span><span style="display:flex;"><span> <span style="color:#f92672">&#34;raw_test_output&#34;</span>: <span style="color:#e6db74">&#34;IndexError: list index out of range&#34;</span>
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></div><p>The important thing is not merely that the attempt failed.</p>
<p>The important thing is that the failure is now machine-readable.</p>
<p>The manager can diagnose it:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-text" data-lang="text"><span style="display:flex;"><span>The candidate changed the iteration semantics and broke mismatched-length behavior.
</span></span></code></pre></div><p>Then the next prompt can be repaired:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-text" data-lang="text"><span style="display:flex;"><span>Preserve zip semantics.
</span></span><span style="display:flex;"><span>Do not assume equal-length vectors.
</span></span><span style="display:flex;"><span>Do not trade correctness for speed.
</span></span></code></pre></div><p>A different candidate might pass correctness but regress the benchmark:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-json" data-lang="json"><span style="display:flex;"><span>{
</span></span><span style="display:flex;"><span> <span style="color:#f92672">&#34;attempt_id&#34;</span>: <span style="color:#e6db74">&#34;attempt_002&#34;</span>,
</span></span><span style="display:flex;"><span> <span style="color:#f92672">&#34;applied&#34;</span>: <span style="color:#66d9ef">true</span>,
</span></span><span style="display:flex;"><span> <span style="color:#f92672">&#34;compiled&#34;</span>: <span style="color:#66d9ef">true</span>,
</span></span><span style="display:flex;"><span> <span style="color:#f92672">&#34;correctness_passed&#34;</span>: <span style="color:#66d9ef">true</span>,
</span></span><span style="display:flex;"><span> <span style="color:#f92672">&#34;benchmark_passed&#34;</span>: <span style="color:#66d9ef">true</span>,
</span></span><span style="display:flex;"><span> <span style="color:#f92672">&#34;baseline_ms&#34;</span>: <span style="color:#ae81ff">100.0</span>,
</span></span><span style="display:flex;"><span> <span style="color:#f92672">&#34;median_ms&#34;</span>: <span style="color:#ae81ff">105.0</span>,
</span></span><span style="display:flex;"><span> <span style="color:#f92672">&#34;speedup&#34;</span>: <span style="color:#ae81ff">-0.05</span>,
</span></span><span style="display:flex;"><span> <span style="color:#f92672">&#34;failure_reason&#34;</span>: <span style="color:#e6db74">&#34;benchmark_regression&#34;</span>
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></div><p>That is a very different kind of evidence.</p>
<p>The code is correct, but it is slower. So the next prompt should not focus on boundary semantics. It should focus on performance discipline:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-text" data-lang="text"><span style="display:flex;"><span>The previous candidate was correct but slower.
</span></span><span style="display:flex;"><span>Avoid extra branching, allocations, sleeps, or unnecessary memory traffic.
</span></span><span style="display:flex;"><span>Target the measured hotspot directly.
</span></span></code></pre></div><p>And if an attempt finally passes both gates:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-json" data-lang="json"><span style="display:flex;"><span>{
</span></span><span style="display:flex;"><span> <span style="color:#f92672">&#34;attempt_id&#34;</span>: <span style="color:#e6db74">&#34;attempt_003&#34;</span>,
</span></span><span style="display:flex;"><span> <span style="color:#f92672">&#34;applied&#34;</span>: <span style="color:#66d9ef">true</span>,
</span></span><span style="display:flex;"><span> <span style="color:#f92672">&#34;compiled&#34;</span>: <span style="color:#66d9ef">true</span>,
</span></span><span style="display:flex;"><span> <span style="color:#f92672">&#34;correctness_passed&#34;</span>: <span style="color:#66d9ef">true</span>,
</span></span><span style="display:flex;"><span> <span style="color:#f92672">&#34;benchmark_passed&#34;</span>: <span style="color:#66d9ef">true</span>,
</span></span><span style="display:flex;"><span> <span style="color:#f92672">&#34;baseline_ms&#34;</span>: <span style="color:#ae81ff">100.0</span>,
</span></span><span style="display:flex;"><span> <span style="color:#f92672">&#34;median_ms&#34;</span>: <span style="color:#ae81ff">84.0</span>,
</span></span><span style="display:flex;"><span> <span style="color:#f92672">&#34;speedup&#34;</span>: <span style="color:#ae81ff">0.16</span>,
</span></span><span style="display:flex;"><span> <span style="color:#f92672">&#34;failure_reason&#34;</span>: <span style="color:#66d9ef">null</span>
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></div><p>then it can be promoted.</p>
<p>Not because Codex said it was better.</p>
<p>Not because the diff looked clever.</p>
<p>Because the evidence survived the gates.</p>
<p>This is the difference between autocomplete and engineering.</p>
<p>Codex Manager does not ask:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-text" data-lang="text"><span style="display:flex;"><span>Does this answer look good?
</span></span></code></pre></div><p>It asks:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-text" data-lang="text"><span style="display:flex;"><span>Did it apply?
</span></span><span style="display:flex;"><span>Did it build?
</span></span><span style="display:flex;"><span>Did it preserve correctness?
</span></span><span style="display:flex;"><span>Did it improve the benchmark?
</span></span><span style="display:flex;"><span>What did we learn if it failed?
</span></span></code></pre></div><p>The final candidate is only the visible output.</p>
<p>The real product is the evidence trail that explains why it was accepted.</p>
<hr>
<h2 id="diagnosis-and-repair-turning-failure-into-the-next-prompt">Diagnosis and Repair: Turning Failure into the Next Prompt</h2>
<p>An important design was the split between diagnosis and repair:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-text" data-lang="text"><span style="display:flex;"><span>AttemptResult → AttemptDiagnosis
</span></span><span style="display:flex;"><span>AttemptDiagnosis → PromptDelta
</span></span></code></pre></div><p>That split became one of the most important architectural choices in the system.</p>
<p>The diagnoser answers:</p>
<blockquote>
<p>What did the evidence show?</p>
</blockquote>
<p>The repair policy answers:</p>
<blockquote>
<p>How should the next prompt change?</p>
</blockquote>
<p>Those are not the same question.</p>
<p>A failed attempt contains raw evidence: exit codes, compiler output, test failures, benchmark numbers, patch-application errors, and metadata from the isolated workspace. The diagnoser’s job is to turn that raw evidence into a clear interpretation. It should say what failed, why it likely failed, how confident the system is, and what lesson should be carried forward.</p>
<p>The repair policy then decides how to mutate the next <code>PromptState</code>.</p>
<p>That separation matters because a test error should not be allowed to improvise the next instruction. The manager remains in control: evidence becomes diagnosis, diagnosis becomes a structured prompt delta, and only then does <code>PromptState</code> evolve.</p>
<p>In other words, failure does not trigger a vague retry.</p>
<p>Failure becomes a <strong>controlled state transition</strong>.</p>
<p>For example, given:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-text" data-lang="text"><span style="display:flex;"><span>failure_reason = &#34;bounds_check_missing&#34;
</span></span></code></pre></div><p>the diagnoser might produce:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-text" data-lang="text"><span style="display:flex;"><span>Candidate removed or weakened boundary handling.
</span></span><span style="display:flex;"><span>The next prompt must preserve boundary semantics and handle non-divisible input sizes.
</span></span></code></pre></div><p>The repair policy then translates that diagnosis into explicit prompt-state changes:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-yaml" data-lang="yaml"><span style="display:flex;"><span><span style="color:#f92672">user_additions</span>:
</span></span><span style="display:flex;"><span> - <span style="color:#ae81ff">Explicitly preserve boundary checks and handle non-divisible input sizes.</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">new_failure_warnings</span>:
</span></span><span style="display:flex;"><span> - <span style="color:#ae81ff">Previous attempt likely failed because boundary guards were missing or weakened.</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">new_banned_moves</span>:
</span></span><span style="display:flex;"><span> - <span style="color:#ae81ff">Assume aligned sizes</span>
</span></span><span style="display:flex;"><span> - <span style="color:#ae81ff">Remove tid/count guards</span>
</span></span></code></pre></div><p>That is very different from saying:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-text" data-lang="text"><span style="display:flex;"><span>Try again.
</span></span></code></pre></div><p>The system now knows <em>what kind</em> of retry it is performing.</p>
<p>A <code>compilation_failed</code> diagnosis produces a different repair:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-yaml" data-lang="yaml"><span style="display:flex;"><span><span style="color:#f92672">system_additions</span>:
</span></span><span style="display:flex;"><span> - <span style="color:#ae81ff">Preserve public interfaces, function names, signatures, buffer bindings, and required imports.</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">user_additions</span>:
</span></span><span style="display:flex;"><span> - <span style="color:#ae81ff">Before changing syntax, compare against the baseline and keep the smallest compilable edit.</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">new_banned_moves</span>:
</span></span><span style="display:flex;"><span> - <span style="color:#ae81ff">Pseudocode</span>
</span></span><span style="display:flex;"><span> - <span style="color:#ae81ff">Undefined symbols</span>
</span></span><span style="display:flex;"><span> - <span style="color:#ae81ff">Changed public interface</span>
</span></span></code></pre></div><p>A <code>benchmark_regression</code> produces a different repair again:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-yaml" data-lang="yaml"><span style="display:flex;"><span><span style="color:#f92672">user_additions</span>:
</span></span><span style="display:flex;"><span> - <span style="color:#ae81ff">The previous candidate was correct but slower.</span>
</span></span><span style="display:flex;"><span> - <span style="color:#ae81ff">Target a smaller hotspot-specific optimization.</span>
</span></span><span style="display:flex;"><span> - <span style="color:#ae81ff">Avoid extra branching, sleeps, allocations, or unnecessary memory traffic.</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">new_failure_warnings</span>:
</span></span><span style="display:flex;"><span> - <span style="color:#ae81ff">Previous candidate regressed benchmark performance.</span>
</span></span></code></pre></div><p>This is the point of the split. The manager does not treat all failures as equal. A syntax failure, a correctness failure, a benchmark regression, and a malformed model response all require different prompt changes.</p>
<p>Once failures are typed this way, the manager can build a small operating manual for itself:</p>
<table>
<thead>
<tr>
<th>Failure</th>
<th>What the diagnoser sees</th>
<th>How the prompt is repaired</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>candidate_generation_failed</code></td>
<td>The executor failed to return a usable candidate</td>
<td>Simplify the output contract; require one valid artifact only</td>
</tr>
<tr>
<td><code>patch_apply_failed</code></td>
<td>The candidate was not a clean diff or touched the wrong file</td>
<td>Require a minimal unified diff against the exact target file</td>
</tr>
<tr>
<td><code>compilation_failed</code></td>
<td>Syntax, imports, interface, or build contract broke</td>
<td>Preserve signatures, imports, bindings, and public interface</td>
</tr>
<tr>
<td><code>correctness_failed</code></td>
<td>Behavior changed even if the code built</td>
<td>Preserve semantics before optimizing speed</td>
</tr>
<tr>
<td><code>bounds_check_missing</code></td>
<td>Boundary or size assumptions broke edge cases</td>
<td>Preserve bounds checks and handle non-divisible sizes</td>
</tr>
<tr>
<td><code>benchmark_regression</code></td>
<td>Candidate was correct but slower</td>
<td>Avoid extra branching, allocation, sync, or memory traffic</td>
</tr>
<tr>
<td><code>benchmark_failed</code></td>
<td>Benchmark crashed or stopped emitting required metrics</td>
<td>Preserve benchmark compatibility and output format</td>
</tr>
</tbody>
</table>
<p>That table is the manager’s memory during a run.</p>
<p>It is not memory in the model weights. It is memory in the surrounding system. The next prompt becomes more constrained because the last attempt produced evidence.</p>
<p>This gives the loop its shape:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-text" data-lang="text"><span style="display:flex;"><span>Attempt fails
</span></span><span style="display:flex;"><span>→ evidence is classified
</span></span><span style="display:flex;"><span>→ diagnosis records the lesson
</span></span><span style="display:flex;"><span>→ repair policy mutates PromptState
</span></span><span style="display:flex;"><span>→ next attempt is generated under better constraints
</span></span></code></pre></div><p>The prompt state evolves through structured deltas, not ad-hoc string rewrites.</p>
<p>That is what makes the process traceable. Every prompt change can be connected back to a specific attempt, a specific failure class, and a specific repair rule. When the final candidate is promoted, we can inspect the path that led there:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-text" data-lang="text"><span style="display:flex;"><span>attempt_001/
</span></span><span style="display:flex;"><span> result.json
</span></span><span style="display:flex;"><span> diagnosis.md
</span></span><span style="display:flex;"><span> next_prompt_delta.md
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>attempt_002/
</span></span><span style="display:flex;"><span> result.json
</span></span><span style="display:flex;"><span> diagnosis.md
</span></span><span style="display:flex;"><span> next_prompt_delta.md
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>attempt_003/
</span></span><span style="display:flex;"><span> result.json
</span></span><span style="display:flex;"><span> diagnosis.md
</span></span><span style="display:flex;"><span> next_prompt_delta.md
</span></span></code></pre></div><p>The final code is not floating in space. It has provenance. The retry is more than a loop around the same mistake.</p>
<hr>
<h2 id="the-staircase-we-built">The Staircase We Built</h2>
<p>We built Codex Manager in layers.</p>
<p>Each layer has one job, and each job removes one source of instability from the system. The result looks like a pipeline because that is what it is: a layered runtime where candidates move from context, to execution, to evidence, to packaging.</p>
<p>This is the current layer stack:</p>
<table>
<thead>
<tr>
<th>Step</th>
<th>Layer</th>
<th>Job</th>
<th>What it stabilizes</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Prompt-state loop</td>
<td>Turn attempt results into prompt updates</td>
<td>Ad-hoc retrying</td>
</tr>
<tr>
<td>2</td>
<td>Runtime contract</td>
<td>Define the engine/facade/profile boundary</td>
<td>Hardcoded execution paths</td>
</tr>
<tr>
<td>3</td>
<td>Shadow execution</td>
<td>Apply and test candidates in isolated workspaces</td>
<td>Blind mutation of real source</td>
</tr>
<tr>
<td>4</td>
<td>Executor registry</td>
<td>Swap mock, scripted, and live candidate generators</td>
<td>Model lock-in</td>
</tr>
<tr>
<td>5</td>
<td>Task packs</td>
<td>Load external task definitions from YAML/JSON</td>
<td>Hardcoded benchmark problems</td>
</tr>
<tr>
<td>6</td>
<td>Run bundles</td>
<td>Preserve complete run artifacts and replay metadata</td>
<td>Unreplayable runs</td>
</tr>
<tr>
<td>7</td>
<td>Command adapter</td>
<td>Run build, correctness, and benchmark commands</td>
<td>Toy-only evaluation</td>
</tr>
<tr>
<td>8</td>
<td>Submission packager</td>
<td>Convert run evidence into judge-ready artifacts</td>
<td>Messy or incomplete submission outputs</td>
</tr>
<tr>
<td>9</td>
<td>Platform adapters</td>
<td>Translate submissions into target platform layouts</td>
<td>Platform-specific branch logic inside the core runtime</td>
</tr>
<tr>
<td>10</td>
<td>Pipeline orchestrator</td>
<td>Run the full workflow as one deterministic sequence</td>
<td>Manual multi-step operation</td>
</tr>
<tr>
<td>11</td>
<td>CLI</td>
<td>Expose the pipeline as terminal commands and profiles</td>
<td>Python-snippet operation under pressure</td>
</tr>
</tbody>
</table>
<p>The important thing is that the layer stack keeps the system understandable. Each part has a narrow responsibility, and the whole thing composes into a pipeline.</p>
<hr>
<h2 id="cold-example-1-a-portable-vector_add-task-pack">Cold Example 1: A Portable <code>vector_add</code> Task Pack</h2>
<p>The task pack is where the system stops being a demo. It is the contract between the outside world and the manager: the problem, source file, allowed patch paths, build command, correctness command, benchmark command, output contract, and known failure modes.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-yaml" data-lang="yaml"><span style="display:flex;"><span><span style="color:#f92672">task_id</span>: <span style="color:#ae81ff">command_vector_add_pack</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">profile</span>: <span style="color:#ae81ff">kernel_optimization</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">goal</span>: <span style="color:#ae81ff">Optimize the command-mode vector_add kernel while preserving correctness.</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">max_attempts</span>: <span style="color:#ae81ff">3</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">execution</span>:
</span></span><span style="display:flex;"><span> <span style="color:#f92672">mode</span>: <span style="color:#ae81ff">command</span>
</span></span><span style="display:flex;"><span> <span style="color:#f92672">source_dir</span>: <span style="color:#ae81ff">source</span>
</span></span><span style="display:flex;"><span> <span style="color:#f92672">target_file</span>: <span style="color:#ae81ff">kernel.py</span>
</span></span><span style="display:flex;"><span> <span style="color:#f92672">allowed_patch_paths</span>:
</span></span><span style="display:flex;"><span> - <span style="color:#ae81ff">kernel.py</span>
</span></span><span style="display:flex;"><span> <span style="color:#f92672">build_command</span>: <span style="color:#ae81ff">python -m py_compile kernel.py</span>
</span></span><span style="display:flex;"><span> <span style="color:#f92672">correctness_command</span>: <span style="color:#ae81ff">python test_kernel.py</span>
</span></span><span style="display:flex;"><span> <span style="color:#f92672">benchmark_command</span>: <span style="color:#ae81ff">python bench_kernel.py</span>
</span></span><span style="display:flex;"><span> <span style="color:#f92672">benchmark_output_format</span>: <span style="color:#ae81ff">key_value</span>
</span></span><span style="display:flex;"><span> <span style="color:#f92672">baseline_key</span>: <span style="color:#ae81ff">baseline_ms</span>
</span></span><span style="display:flex;"><span> <span style="color:#f92672">score_key</span>: <span style="color:#ae81ff">median_ms</span>
</span></span><span style="display:flex;"><span> <span style="color:#f92672">higher_is_better</span>: <span style="color:#66d9ef">false</span>
</span></span><span style="display:flex;"><span> <span style="color:#f92672">baseline_ms</span>: <span style="color:#ae81ff">100.0</span>
</span></span><span style="display:flex;"><span> <span style="color:#f92672">target_speedup</span>: <span style="color:#ae81ff">0.10</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">context</span>:
</span></span><span style="display:flex;"><span> <span style="color:#f92672">operation_name</span>: <span style="color:#ae81ff">vector_add</span>
</span></span><span style="display:flex;"><span> <span style="color:#f92672">hardware_target</span>: <span style="color:#ae81ff">deterministic_python_command</span>
</span></span><span style="display:flex;"><span> <span style="color:#f92672">output_contract</span>: <span style="color:#ae81ff">Return one valid unified diff against kernel.py and nothing else.</span>
</span></span><span style="display:flex;"><span> <span style="color:#f92672">correctness_contract</span>:
</span></span><span style="display:flex;"><span> - <span style="color:#ae81ff">Preserve vector_add(a, b) behavior.</span>
</span></span><span style="display:flex;"><span> - <span style="color:#ae81ff">Do not modify tests or benchmarks.</span>
</span></span><span style="display:flex;"><span> - <span style="color:#ae81ff">Handle empty vectors.</span>
</span></span><span style="display:flex;"><span> - <span style="color:#ae81ff">Handle mismatched vector lengths using zip semantics.</span>
</span></span><span style="display:flex;"><span> <span style="color:#f92672">benchmark_contract</span>:
</span></span><span style="display:flex;"><span> - <span style="color:#ae81ff">Benchmark output must print baseline_ms=&lt;float&gt;.</span>
</span></span><span style="display:flex;"><span> - <span style="color:#ae81ff">Benchmark output must print median_ms=&lt;float&gt;.</span>
</span></span><span style="display:flex;"><span> - <span style="color:#ae81ff">Lower median_ms is better.</span>
</span></span><span style="display:flex;"><span> <span style="color:#f92672">known_failure_modes</span>:
</span></span><span style="display:flex;"><span> - <span style="color:#ae81ff">Touching test files invalidates the candidate.</span>
</span></span><span style="display:flex;"><span> - <span style="color:#ae81ff">Syntax errors fail the build gate.</span>
</span></span><span style="display:flex;"><span> - <span style="color:#ae81ff">Removing zip semantics may break mismatched length behavior.</span>
</span></span></code></pre></div><p>There is no hidden Python factory here. The task defines its own source, target, tests, benchmark, output contract, failure modes, and scoring semantics.</p>
<p>This is important because the task is no longer hardcoded into Python. The manager can ingest it, build a context pack, run the same loop, and produce the same audit trail for any task that follows the contract.</p>
<hr>
<h2 id="cold-example-2-command-driven-evaluation">Cold Example 2: Command-Driven Evaluation</h2>
<p>The command runner turns a candidate diff into evidence.</p>
<p>For each candidate, it runs a strict five-phase pipeline:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-text" data-lang="text"><span style="display:flex;"><span>Patch → Build → Correctness → Benchmark → Metric parse
</span></span></code></pre></div><p>The benchmark harness emits simple key-value output:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-text" data-lang="text"><span style="display:flex;"><span>baseline_ms=100.0
</span></span><span style="display:flex;"><span>median_ms=84.0
</span></span></code></pre></div><p>The parser computes <code>speedup = (baseline_ms - median_ms) / baseline_ms</code>, giving <code>(100.0 - 84.0) / 100.0 = 0.16</code>. A 16% speedup only matters if correctness passed first.</p>
<p>Here’s the actual attempt chain observed in a mock run:</p>
<ul>
<li><strong>Attempt 1:</strong> patch applies, build passes, correctness fails → <code>failure_reason = correctness_failed</code> → prompt adds: <em>preserve zip semantics</em></li>
<li><strong>Attempt 2:</strong> correctness passes, benchmark regresses → <code>failure_reason = benchmark_regression</code> → prompt adds: <em>avoid extra branching and allocations</em></li>
<li><strong>Attempt 3:</strong> correctness passes, benchmark improves → <strong>promoted</strong></li>
</ul>
<p>This deterministic progression proves that the manager can recover from both safety and performance failures without human intervention.</p>
<hr>
<h2 id="cold-example-3-one-command-pipeline">Cold Example 3: One Command Pipeline</h2>
<p>By the end, the whole workflow became one terminal command:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>writer codex-manager pipeline run <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span> --task examples/codex_manager/command_vector_add/task.yaml <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span> --output-root runs/blog_vector_add_smoke <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span> --platform generic_command <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span> --executor mock <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span> --create-zip <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span> --overwrite
</span></span></code></pre></div><p>A real smoke run produced:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-text" data-lang="text"><span style="display:flex;"><span>Pipeline run
</span></span><span style="display:flex;"><span> Status: completed
</span></span><span style="display:flex;"><span> Pipeline id: pipe_e140aaaa0ae6
</span></span><span style="display:flex;"><span> Run id: cmrun_dbc92100fcb7
</span></span><span style="display:flex;"><span> Submission id: submission_384f757e2f35
</span></span><span style="display:flex;"><span> Platform export id: export_189cb76315d3
</span></span><span style="display:flex;"><span> Submission zip path: runs/blog_vector_add_smoke/submission.zip
</span></span><span style="display:flex;"><span> Pipeline report: runs/blog_vector_add_smoke/pipeline_report.md
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Pipeline validation
</span></span><span style="display:flex;"><span> Valid: True
</span></span></code></pre></div><p>That single command runs:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-text" data-lang="text"><span style="display:flex;"><span>task pack load
</span></span><span style="display:flex;"><span>→ prompt-state optimization
</span></span><span style="display:flex;"><span>→ command execution
</span></span><span style="display:flex;"><span>→ bundle generation
</span></span><span style="display:flex;"><span>→ submission packaging
</span></span><span style="display:flex;"><span>→ platform export
</span></span><span style="display:flex;"><span>→ validation
</span></span></code></pre></div><hr>
<h2 id="the-artifact-trail-evidence-has-structure">The Artifact Trail: Evidence Has Structure</h2>
<p>By the time a run finishes, Codex Manager has not only produced a candidate. It has produced a trail.</p>
<p>That trail matters because agentic code systems are otherwise hard to inspect. A model may return a plausible answer, but without the surrounding evidence we cannot tell whether the answer was lucky, verified, overfit, unsafe, or simply accepted because no one looked closely enough.</p>
<p>Codex Manager writes the evidence down.</p>
<p>At the attempt level, each executed attempt gets its own directory:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-text" data-lang="text"><span style="display:flex;"><span>attempts/
</span></span><span style="display:flex;"><span> attempt_001/
</span></span><span style="display:flex;"><span> prompt.md
</span></span><span style="display:flex;"><span> result.json
</span></span><span style="display:flex;"><span> diagnosis.md
</span></span><span style="display:flex;"><span> next_prompt_delta.md
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> attempt_002/
</span></span><span style="display:flex;"><span> prompt.md
</span></span><span style="display:flex;"><span> result.json
</span></span><span style="display:flex;"><span> diagnosis.md
</span></span><span style="display:flex;"><span> next_prompt_delta.md
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> attempt_003/
</span></span><span style="display:flex;"><span> prompt.md
</span></span><span style="display:flex;"><span> result.json
</span></span><span style="display:flex;"><span> diagnosis.md
</span></span><span style="display:flex;"><span> next_prompt_delta.md
</span></span></code></pre></div><p>That directory is the chain of custody for each candidate.</p>
<ul>
<li><code>prompt.md</code> shows what Codex saw.</li>
<li><code>result.json</code> shows what happened when the candidate was executed.</li>
<li><code>diagnosis.md</code> explains what the evidence meant.</li>
<li><code>next_prompt_delta.md</code> shows how the next prompt changed.</li>
</ul>
<p>A run also keeps a separate timeline of prompt states:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-text" data-lang="text"><span style="display:flex;"><span>prompt_states/
</span></span><span style="display:flex;"><span> attempt_001/
</span></span><span style="display:flex;"><span> prompt.md
</span></span><span style="display:flex;"><span> attempt_002/
</span></span><span style="display:flex;"><span> prompt.md
</span></span><span style="display:flex;"><span> attempt_003/
</span></span><span style="display:flex;"><span> prompt.md
</span></span><span style="display:flex;"><span> attempt_004/
</span></span><span style="display:flex;"><span> prompt.md
</span></span></code></pre></div><p>That distinction matters.</p>
<p><code>attempts/</code> contains candidates that were actually executed. <code>prompt_states/</code> contains the evolving state of the run, including the next prompt state that would be used if another attempt were needed.</p>
<p>So the final unexecuted next state can still be inspected, but it does not masquerade as an executed attempt.</p>
<p>This gives the artifact model clean boundaries:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-text" data-lang="text"><span style="display:flex;"><span>attempts/
</span></span><span style="display:flex;"><span> attempt_001/
</span></span><span style="display:flex;"><span> prompt.md
</span></span><span style="display:flex;"><span> result.json
</span></span><span style="display:flex;"><span> diagnosis.md
</span></span><span style="display:flex;"><span> next_prompt_delta.md
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>prompt_states/
</span></span><span style="display:flex;"><span> attempt_004/
</span></span><span style="display:flex;"><span> prompt.md
</span></span></code></pre></div><p>At the run level, Codex Manager writes:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-text" data-lang="text"><span style="display:flex;"><span>run_manifest.json
</span></span><span style="display:flex;"><span>context_pack.md
</span></span><span style="display:flex;"><span>PROMPTS.log
</span></span><span style="display:flex;"><span>report.md
</span></span><span style="display:flex;"><span>validation.json
</span></span><span style="display:flex;"><span>best/
</span></span></code></pre></div><p>At the submission level, it writes:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-text" data-lang="text"><span style="display:flex;"><span>submission_manifest.json
</span></span><span style="display:flex;"><span>README.md
</span></span><span style="display:flex;"><span>summary.json
</span></span><span style="display:flex;"><span>prompt_evolution.json
</span></span><span style="display:flex;"><span>evidence/
</span></span><span style="display:flex;"><span>best/
</span></span></code></pre></div><p>And once the full pipeline runs, it writes:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-text" data-lang="text"><span style="display:flex;"><span>pipeline_manifest.json
</span></span><span style="display:flex;"><span>pipeline_summary.json
</span></span><span style="display:flex;"><span>pipeline_report.md
</span></span><span style="display:flex;"><span>pipeline_events.jsonl
</span></span><span style="display:flex;"><span>task_run/
</span></span><span style="display:flex;"><span>submission/
</span></span><span style="display:flex;"><span>platform_export/
</span></span></code></pre></div><p>The pipeline manifest ties the whole chain together with IDs and hashes:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-json" data-lang="json"><span style="display:flex;"><span>{
</span></span><span style="display:flex;"><span> <span style="color:#f92672">&#34;status&#34;</span>: <span style="color:#e6db74">&#34;completed&#34;</span>,
</span></span><span style="display:flex;"><span> <span style="color:#f92672">&#34;pipeline_id&#34;</span>: <span style="color:#e6db74">&#34;pipe_5298de9da2df&#34;</span>,
</span></span><span style="display:flex;"><span> <span style="color:#f92672">&#34;run_id&#34;</span>: <span style="color:#e6db74">&#34;cmrun_b608c9be1db5&#34;</span>,
</span></span><span style="display:flex;"><span> <span style="color:#f92672">&#34;submission_id&#34;</span>: <span style="color:#e6db74">&#34;submission_01281797e2a5&#34;</span>,
</span></span><span style="display:flex;"><span> <span style="color:#f92672">&#34;platform_export_id&#34;</span>: <span style="color:#e6db74">&#34;export_efdbf4e960b2&#34;</span>,
</span></span><span style="display:flex;"><span> <span style="color:#f92672">&#34;chain_of_custody&#34;</span>: {
</span></span><span style="display:flex;"><span> <span style="color:#f92672">&#34;run_bundle&#34;</span>: <span style="color:#e6db74">&#34;446b95950ed91687a24016450ff310e9bb37b80a44794147c053416b892ba214&#34;</span>,
</span></span><span style="display:flex;"><span> <span style="color:#f92672">&#34;submission&#34;</span>: <span style="color:#e6db74">&#34;9afec5d1f8f7587e491fd3f7264495a6138a1a881c27e1b2bd30535fa20cee52&#34;</span>,
</span></span><span style="display:flex;"><span> <span style="color:#f92672">&#34;platform_export&#34;</span>: <span style="color:#e6db74">&#34;6960142bad20b2d16b60693bc111e9c2b59bc7a9dddac9b439ef0b53389c4bb8&#34;</span>
</span></span><span style="display:flex;"><span> }
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></div><p>That is the point of the artifact trail.</p>
<p>The system is not asking anyone to trust a generated file. It preserves the context, the candidate, the execution result, the diagnosis, the repair, the submission, and the export.</p>
<p>A judge can inspect it. A developer can replay it. A future run can use the same evidence to improve the next context.</p>
<p>The final code is only the visible tip of the run. The artifact trail is the proof that it deserved to survive.</p>
<hr>
<h2 id="make-the-ai-work-harder">Make the AI Work Harder</h2>
<p>The point of Codex Manager is to make the AI work harder.</p>
<p>A normal coding assistant can produce an answer and move on. If the answer is wrong, the burden falls back on the human: find the bug, explain the failure, rewrite the prompt, run the test again, decide whether the next version is better.</p>
<p>That is useful, but it is still mostly human-managed.</p>
<p>For this hackathon, the challenge was framed around <strong>context</strong>. Our interpretation was simple: if context is the thing being judged, then the system should not rely on a human manually carrying that context from one attempt to the next. The system itself should preserve the context, update it, and force the next attempt to deal with what happened before.</p>
<p>That is what Codex Manager is trying to demonstrate.</p>
<p>It gives the AI a structured environment where it cannot simply produce code and disappear. Every candidate has to pass through the same loop:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-text" data-lang="text"><span style="display:flex;"><span>generate candidate
</span></span><span style="display:flex;"><span>→ apply it safely
</span></span><span style="display:flex;"><span>→ build it
</span></span><span style="display:flex;"><span>→ test correctness
</span></span><span style="display:flex;"><span>→ benchmark it
</span></span><span style="display:flex;"><span>→ diagnose failure
</span></span><span style="display:flex;"><span>→ repair the next prompt
</span></span><span style="display:flex;"><span>→ try again under better constraints
</span></span></code></pre></div><p>The model still proposes the code. But the surrounding system makes the model face evidence.</p>
<p>If the model returns prose instead of a diff, the next prompt gets stricter.</p>
<p>If the candidate breaks correctness, the next prompt carries that lesson.</p>
<p>If the candidate passes correctness but slows the benchmark, the next prompt changes again.</p>
<p>If the candidate succeeds, the system promotes it and preserves the trail.</p>
<p>This is what we mean by making the AI work harder. We are not just asking it for a better answer. We are building the conditions under which it has to produce one.</p>
<p>The manager gives the AI something closer to an external working memory:</p>
<ul>
<li>what the task is</li>
<li>what the output contract is</li>
<li>what failed before</li>
<li>what moves are banned</li>
<li>what patterns should be preserved</li>
<li>what the benchmark actually measured</li>
<li>what evidence is required before promotion</li>
</ul>
<p>That is the context: an evolving control system where each attempt leaves evidence that shapes the next one.</p>
<pre class="mermaid">
flowchart TD
A[&#34;🧠 PromptState&#34;] --&gt; B[&#34;🤖 Generate Candidate&#34;]
B --&gt; C[&#34;🛡️ Apply Candidate&lt;br/&gt;in Isolated Workspace&#34;]
C --&gt; D[&#34;🔍 Validate Attempt&#34;]
D --&gt; E{&#34;Passed?&#34;}
E -- No --&gt; F[&#34;🩺 Diagnose Failure&#34;]
F --&gt; G[&#34;🔄 Repair PromptState&#34;]
G --&gt; A
E -- Yes --&gt; H[&#34;✅ Promote Candidate&#34;]
H --&gt; I[&#34;🎯 Verified Solution&#34;]
subgraph Validation
D1[&#34;⚙️ Build / Compile&#34;]
D2[&#34;🧪 Correctness Tests&#34;]
D3[&#34;📊 Benchmark / Performance&#34;]
end
D --&gt; D1
D --&gt; D2
D --&gt; D3
classDef state fill:#e0f0ff,stroke:#3a6ea5,stroke-width:2px,color:#1a2b3c
classDef evidence fill:#fff7e0,stroke:#d9a34a,stroke-width:2px,color:#4a3a1a
classDef gate fill:#e6ffe6,stroke:#4a9d4a,stroke-width:2px,color:#1a3c1a
class A,G state
class B,F,I evidence
class C,D,E,H gate
class D1,D2,D3 gate
</pre>
<p>This is how we chose to approach the hackathon. If the problem is too broad or too difficult to solve reliably by hand, then the useful demonstration is a system that lets the AI iterate under constraint.</p>
<p>It generates a candidate, tests it, records what happened, repairs the next prompt state, and tries again.</p>
<p>It may reach the final solution. It may not. But it gives the AI a structured way to improve its attempts, and it leaves behind artifacts that show the path it took.</p>
<p>That is our answer to the “context, not code” framing.</p>
<hr>
<h2 id="what-comes-next-applying-the-manager">What Comes Next: Applying the Manager</h2>
<p>The next step is to apply Codex Manager to harder tasks.</p>
<p>The shape is now in place:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-text" data-lang="text"><span style="display:flex;"><span>Task Pack
</span></span><span style="display:flex;"><span>→ PromptState
</span></span><span style="display:flex;"><span>→ Candidate
</span></span><span style="display:flex;"><span>→ Isolated Execution
</span></span><span style="display:flex;"><span>→ Evidence
</span></span><span style="display:flex;"><span>→ Diagnosis
</span></span><span style="display:flex;"><span>→ PromptDelta
</span></span><span style="display:flex;"><span>→ Run Bundle
</span></span><span style="display:flex;"><span>→ Submission
</span></span><span style="display:flex;"><span>→ Platform Export
</span></span></code></pre></div><p>A new target can bring a new source file, a new build command, a new correctness harness, a new benchmark, and a new platform export. The prompt-state loop remains the same.</p>
<p>For a real kernel task, the path is straightforward:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-text" data-lang="text"><span style="display:flex;"><span>Task Pack
</span></span><span style="display:flex;"><span>→ Command Mode
</span></span><span style="display:flex;"><span>→ Metal build command
</span></span><span style="display:flex;"><span>→ Metal correctness harness
</span></span><span style="display:flex;"><span>→ Metal benchmark command
</span></span><span style="display:flex;"><span>→ same PromptState loop
</span></span></code></pre></div><p>That is the point of the architecture.
The hackathon was the forcing function. The pattern is the output.</p>
<hr>
<hr>
<h2 id="references">References</h2>
<p><a href="https://huggingface.co/humanitys-last-hackathon?utm_source=chatgpt.com">Humanity’s Last Hackathon</a></p>
<p><a href="https://www.youtube.com/watch?v=xRFuPkp4iP8">How To Win Humanity&rsquo;s Last Hackathon - The hardest agent contest in AI.</a></p>
<p><a href="https://developers.openai.com/codex">OpenAI Codex Documentation</a> OpenAI’s documentation for Codex as a coding agent for software development. Useful background for readers who want to understand the Codex product surface and workflow model.</p>
<p><a href="https://developers.openai.com/codex/cli">Codex CLI Documentation</a> Documentation for running Codex locally from the terminal. This is especially relevant to the Codex Manager idea because it frames Codex as a coding agent that can read, change, and run code in a local directory.</p>
<p><a href="https://developers.openai.com/codex/cli/reference">Codex CLI Reference</a> Command and flag reference for Codex CLI. Useful for readers who want to compare Codex Manager’s CLI/pipeline approach with OpenAI’s Codex CLI surface.</p>
<p><a href="https://developers.openai.com/codex/cloud">Codex Web / Cloud Documentation</a> Documentation for delegating coding tasks to Codex in a cloud environment.</p>
<p><a href="https://developers.openai.com/codex/skills">Codex Skills Documentation</a> Documentation on Codex skills and reusable workflows. Relevant to the broader idea of treating context and workflow structure as first-class parts of agentic coding.</p>
<hr>
<h2 id="appendix-a-the-codex-manager-loop-in-pseudo-code">Appendix A: The Codex Manager Loop in Pseudo-Code</h2>
<p>The full implementation has engines, facades, registries, task packs, validators, run bundles, submissions, platform adapters, and a CLI. But the core idea is much smaller.</p>
<p>At the center is one loop:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-text" data-lang="text"><span style="display:flex;"><span>PromptState
</span></span><span style="display:flex;"><span>→ Candidate
</span></span><span style="display:flex;"><span>→ AttemptResult
</span></span><span style="display:flex;"><span>→ AttemptDiagnosis
</span></span><span style="display:flex;"><span>→ PromptDelta
</span></span><span style="display:flex;"><span>→ next PromptState
</span></span></code></pre></div><p>Here is that loop in pseudo-code.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#66d9ef">def</span> <span style="color:#a6e22e">solve</span>(task_pack, executor, profile, max_attempts):
</span></span><span style="display:flex;"><span> <span style="color:#e6db74">&#34;&#34;&#34;
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74"> Solve a task by evolving PromptState, not by trusting generated code.
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74"> &#34;&#34;&#34;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> <span style="color:#75715e"># 1. Load task and build initial context.</span>
</span></span><span style="display:flex;"><span> task <span style="color:#f92672">=</span> load_task_pack(task_pack)
</span></span><span style="display:flex;"><span> context_pack <span style="color:#f92672">=</span> build_context_pack(task)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> state <span style="color:#f92672">=</span> PromptState(
</span></span><span style="display:flex;"><span> task_id<span style="color:#f92672">=</span>task<span style="color:#f92672">.</span>id,
</span></span><span style="display:flex;"><span> context_pack<span style="color:#f92672">=</span>context_pack,
</span></span><span style="display:flex;"><span> prior_lessons<span style="color:#f92672">=</span>[],
</span></span><span style="display:flex;"><span> failure_warnings<span style="color:#f92672">=</span>[],
</span></span><span style="display:flex;"><span> banned_moves<span style="color:#f92672">=</span>[],
</span></span><span style="display:flex;"><span> success_patterns<span style="color:#f92672">=</span>[],
</span></span><span style="display:flex;"><span> output_contract<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;Return one valid unified diff and nothing else.&#34;</span>,
</span></span><span style="display:flex;"><span> )
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> attempts <span style="color:#f92672">=</span> []
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> <span style="color:#75715e"># 2. Iterate until budget is exhausted or a verified candidate is found.</span>
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">for</span> attempt_index <span style="color:#f92672">in</span> range(max_attempts):
</span></span><span style="display:flex;"><span> <span style="color:#75715e"># Codex is a candidate generator, not the source of truth.</span>
</span></span><span style="display:flex;"><span> candidate <span style="color:#f92672">=</span> executor<span style="color:#f92672">.</span>generate(state)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> <span style="color:#75715e"># The profile decides how this task is evaluated.</span>
</span></span><span style="display:flex;"><span> <span style="color:#75715e"># For command-mode tasks, this means:</span>
</span></span><span style="display:flex;"><span> <span style="color:#75715e"># patch -&gt; build -&gt; correctness -&gt; benchmark -&gt; metrics</span>
</span></span><span style="display:flex;"><span> result <span style="color:#f92672">=</span> profile<span style="color:#f92672">.</span>run_candidate(
</span></span><span style="display:flex;"><span> task<span style="color:#f92672">=</span>task,
</span></span><span style="display:flex;"><span> state<span style="color:#f92672">=</span>state,
</span></span><span style="display:flex;"><span> candidate<span style="color:#f92672">=</span>candidate,
</span></span><span style="display:flex;"><span> )
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> attempts<span style="color:#f92672">.</span>append(result)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> <span style="color:#75715e"># A candidate only survives if it passes the gates.</span>
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">if</span> result<span style="color:#f92672">.</span>correctness_passed <span style="color:#f92672">and</span> result<span style="color:#f92672">.</span>benchmark_passed <span style="color:#f92672">and</span> result<span style="color:#f92672">.</span>speedup <span style="color:#f92672">&gt;</span> <span style="color:#ae81ff">0</span>:
</span></span><span style="display:flex;"><span> promote(result)
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">break</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> <span style="color:#75715e"># 3. Convert evidence into a diagnosis.</span>
</span></span><span style="display:flex;"><span> diagnosis <span style="color:#f92672">=</span> diagnose(result)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> <span style="color:#75715e"># 4. Convert diagnosis into a prompt delta.</span>
</span></span><span style="display:flex;"><span> delta <span style="color:#f92672">=</span> repair_prompt(diagnosis)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> <span style="color:#75715e"># 5. Produce the next PromptState.</span>
</span></span><span style="display:flex;"><span> state <span style="color:#f92672">=</span> apply_delta(state, delta)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> <span style="color:#75715e"># 6. Preserve the evidence trail.</span>
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">return</span> write_run_bundle(
</span></span><span style="display:flex;"><span> task<span style="color:#f92672">=</span>task,
</span></span><span style="display:flex;"><span> attempts<span style="color:#f92672">=</span>attempts,
</span></span><span style="display:flex;"><span> final_state<span style="color:#f92672">=</span>state,
</span></span><span style="display:flex;"><span> )
</span></span></code></pre></div><p>That is the heart of the system.</p>
<p>Codex generates candidates. The manager turns those candidates into evidence. The evidence changes the next prompt.</p>
<hr>
<h3 id="the-candidate-is-not-trusted">The Candidate Is Not Trusted</h3>
<p>The executor only returns text:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#66d9ef">class</span> <span style="color:#a6e22e">CandidateExecutor</span>:
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">def</span> <span style="color:#a6e22e">generate</span>(self, state: PromptState) <span style="color:#f92672">-&gt;</span> str:
</span></span><span style="display:flex;"><span> <span style="color:#e6db74">&#34;&#34;&#34;
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74"> Return a candidate artifact.
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74"> Usually this is a unified diff.
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74"> It may come from a mock executor, a scripted executor,
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74"> or a live Codex/OpenAI-compatible executor.
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74"> &#34;&#34;&#34;</span>
</span></span><span style="display:flex;"><span> <span style="color:#f92672">...</span>
</span></span></code></pre></div><p>The executor does not validate the candidate. It does not repair the prompt. It does not promote anything.</p>
<p>It only generates.</p>
<hr>
<h3 id="the-profile-turns-a-candidate-into-evidence">The Profile Turns a Candidate into Evidence</h3>
<p>A profile knows how to evaluate a task.</p>
<p>For a command-mode task, evaluation looks like this:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#66d9ef">def</span> <span style="color:#a6e22e">run_candidate</span>(task, state, candidate_diff):
</span></span><span style="display:flex;"><span> workspace <span style="color:#f92672">=</span> create_isolated_workspace(task<span style="color:#f92672">.</span>source_dir)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> patch <span style="color:#f92672">=</span> apply_patch(
</span></span><span style="display:flex;"><span> workspace<span style="color:#f92672">=</span>workspace,
</span></span><span style="display:flex;"><span> patch_text<span style="color:#f92672">=</span>candidate_diff,
</span></span><span style="display:flex;"><span> allowed_paths<span style="color:#f92672">=</span>task<span style="color:#f92672">.</span>allowed_patch_paths,
</span></span><span style="display:flex;"><span> )
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">if</span> <span style="color:#f92672">not</span> patch<span style="color:#f92672">.</span>applied:
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">return</span> AttemptResult(
</span></span><span style="display:flex;"><span> applied<span style="color:#f92672">=</span><span style="color:#66d9ef">False</span>,
</span></span><span style="display:flex;"><span> compiled<span style="color:#f92672">=</span><span style="color:#66d9ef">False</span>,
</span></span><span style="display:flex;"><span> correctness_passed<span style="color:#f92672">=</span><span style="color:#66d9ef">False</span>,
</span></span><span style="display:flex;"><span> benchmark_passed<span style="color:#f92672">=</span><span style="color:#66d9ef">False</span>,
</span></span><span style="display:flex;"><span> failure_reason<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;patch_apply_failed&#34;</span>,
</span></span><span style="display:flex;"><span> raw_test_output<span style="color:#f92672">=</span>patch<span style="color:#f92672">.</span>error,
</span></span><span style="display:flex;"><span> )
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> build <span style="color:#f92672">=</span> run_command(task<span style="color:#f92672">.</span>build_command, cwd<span style="color:#f92672">=</span>workspace)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">if</span> <span style="color:#f92672">not</span> build<span style="color:#f92672">.</span>passed:
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">return</span> AttemptResult(
</span></span><span style="display:flex;"><span> applied<span style="color:#f92672">=</span><span style="color:#66d9ef">True</span>,
</span></span><span style="display:flex;"><span> compiled<span style="color:#f92672">=</span><span style="color:#66d9ef">False</span>,
</span></span><span style="display:flex;"><span> correctness_passed<span style="color:#f92672">=</span><span style="color:#66d9ef">False</span>,
</span></span><span style="display:flex;"><span> benchmark_passed<span style="color:#f92672">=</span><span style="color:#66d9ef">False</span>,
</span></span><span style="display:flex;"><span> failure_reason<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;compilation_failed&#34;</span>,
</span></span><span style="display:flex;"><span> raw_test_output<span style="color:#f92672">=</span>build<span style="color:#f92672">.</span>output,
</span></span><span style="display:flex;"><span> )
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> correctness <span style="color:#f92672">=</span> run_command(task<span style="color:#f92672">.</span>correctness_command, cwd<span style="color:#f92672">=</span>workspace)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">if</span> <span style="color:#f92672">not</span> correctness<span style="color:#f92672">.</span>passed:
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">return</span> AttemptResult(
</span></span><span style="display:flex;"><span> applied<span style="color:#f92672">=</span><span style="color:#66d9ef">True</span>,
</span></span><span style="display:flex;"><span> compiled<span style="color:#f92672">=</span><span style="color:#66d9ef">True</span>,
</span></span><span style="display:flex;"><span> correctness_passed<span style="color:#f92672">=</span><span style="color:#66d9ef">False</span>,
</span></span><span style="display:flex;"><span> benchmark_passed<span style="color:#f92672">=</span><span style="color:#66d9ef">False</span>,
</span></span><span style="display:flex;"><span> failure_reason<span style="color:#f92672">=</span>classify_correctness_failure(correctness<span style="color:#f92672">.</span>output),
</span></span><span style="display:flex;"><span> raw_test_output<span style="color:#f92672">=</span>correctness<span style="color:#f92672">.</span>output,
</span></span><span style="display:flex;"><span> )
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> benchmark <span style="color:#f92672">=</span> run_command(task<span style="color:#f92672">.</span>benchmark_command, cwd<span style="color:#f92672">=</span>workspace)
</span></span><span style="display:flex;"><span> metrics <span style="color:#f92672">=</span> parse_benchmark_output(benchmark<span style="color:#f92672">.</span>output)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">if</span> <span style="color:#f92672">not</span> benchmark<span style="color:#f92672">.</span>passed <span style="color:#f92672">or</span> <span style="color:#f92672">not</span> metrics<span style="color:#f92672">.</span>valid:
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">return</span> AttemptResult(
</span></span><span style="display:flex;"><span> applied<span style="color:#f92672">=</span><span style="color:#66d9ef">True</span>,
</span></span><span style="display:flex;"><span> compiled<span style="color:#f92672">=</span><span style="color:#66d9ef">True</span>,
</span></span><span style="display:flex;"><span> correctness_passed<span style="color:#f92672">=</span><span style="color:#66d9ef">True</span>,
</span></span><span style="display:flex;"><span> benchmark_passed<span style="color:#f92672">=</span><span style="color:#66d9ef">False</span>,
</span></span><span style="display:flex;"><span> failure_reason<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;benchmark_failed&#34;</span>,
</span></span><span style="display:flex;"><span> raw_benchmark_output<span style="color:#f92672">=</span>benchmark<span style="color:#f92672">.</span>output,
</span></span><span style="display:flex;"><span> )
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> speedup <span style="color:#f92672">=</span> compute_speedup(metrics)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">return</span> AttemptResult(
</span></span><span style="display:flex;"><span> applied<span style="color:#f92672">=</span><span style="color:#66d9ef">True</span>,
</span></span><span style="display:flex;"><span> compiled<span style="color:#f92672">=</span><span style="color:#66d9ef">True</span>,
</span></span><span style="display:flex;"><span> correctness_passed<span style="color:#f92672">=</span><span style="color:#66d9ef">True</span>,
</span></span><span style="display:flex;"><span> benchmark_passed<span style="color:#f92672">=</span><span style="color:#66d9ef">True</span>,
</span></span><span style="display:flex;"><span> baseline_ms<span style="color:#f92672">=</span>metrics[<span style="color:#e6db74">&#34;baseline_ms&#34;</span>],
</span></span><span style="display:flex;"><span> median_ms<span style="color:#f92672">=</span>metrics[<span style="color:#e6db74">&#34;median_ms&#34;</span>],
</span></span><span style="display:flex;"><span> speedup<span style="color:#f92672">=</span>speedup,
</span></span><span style="display:flex;"><span> failure_reason<span style="color:#f92672">=</span><span style="color:#66d9ef">None</span> <span style="color:#66d9ef">if</span> speedup <span style="color:#f92672">&gt;</span> <span style="color:#ae81ff">0</span> <span style="color:#66d9ef">else</span> <span style="color:#e6db74">&#34;benchmark_regression&#34;</span>,
</span></span><span style="display:flex;"><span> raw_test_output<span style="color:#f92672">=</span>correctness<span style="color:#f92672">.</span>output,
</span></span><span style="display:flex;"><span> raw_benchmark_output<span style="color:#f92672">=</span>benchmark<span style="color:#f92672">.</span>output,
</span></span><span style="display:flex;"><span> )
</span></span></code></pre></div><p>The key rule is:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#66d9ef">if</span> <span style="color:#f92672">not</span> correctness<span style="color:#f92672">.</span>passed:
</span></span><span style="display:flex;"><span> do_not_run_benchmark()
</span></span></code></pre></div><p>A faster wrong answer is not an optimization.</p>
<hr>
<h3 id="diagnosis-interprets-evidence">Diagnosis Interprets Evidence</h3>
<p>The diagnoser does not edit the prompt. It only classifies what happened.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#66d9ef">def</span> <span style="color:#a6e22e">diagnose</span>(result):
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">if</span> result<span style="color:#f92672">.</span>failure_reason <span style="color:#f92672">==</span> <span style="color:#e6db74">&#34;patch_apply_failed&#34;</span>:
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">return</span> AttemptDiagnosis(
</span></span><span style="display:flex;"><span> failure_class<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;patch_apply_failed&#34;</span>,
</span></span><span style="display:flex;"><span> prompt_lesson<span style="color:#f92672">=</span>(
</span></span><span style="display:flex;"><span> <span style="color:#e6db74">&#34;The candidate was not a clean patch. &#34;</span>
</span></span><span style="display:flex;"><span> <span style="color:#e6db74">&#34;The next prompt must require one valid unified diff against the target file.&#34;</span>
</span></span><span style="display:flex;"><span> ),
</span></span><span style="display:flex;"><span> )
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">if</span> result<span style="color:#f92672">.</span>failure_reason <span style="color:#f92672">==</span> <span style="color:#e6db74">&#34;compilation_failed&#34;</span>:
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">return</span> AttemptDiagnosis(
</span></span><span style="display:flex;"><span> failure_class<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;compilation_failed&#34;</span>,
</span></span><span style="display:flex;"><span> prompt_lesson<span style="color:#f92672">=</span>(
</span></span><span style="display:flex;"><span> <span style="color:#e6db74">&#34;The candidate failed to build. &#34;</span>
</span></span><span style="display:flex;"><span> <span style="color:#e6db74">&#34;The next prompt must preserve valid syntax, imports, function names, and public interfaces.&#34;</span>
</span></span><span style="display:flex;"><span> ),
</span></span><span style="display:flex;"><span> )
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">if</span> result<span style="color:#f92672">.</span>failure_reason <span style="color:#f92672">==</span> <span style="color:#e6db74">&#34;correctness_failed&#34;</span>:
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">return</span> AttemptDiagnosis(
</span></span><span style="display:flex;"><span> failure_class<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;correctness_failed&#34;</span>,
</span></span><span style="display:flex;"><span> prompt_lesson<span style="color:#f92672">=</span>(
</span></span><span style="display:flex;"><span> <span style="color:#e6db74">&#34;The candidate changed behavior. &#34;</span>
</span></span><span style="display:flex;"><span> <span style="color:#e6db74">&#34;The next prompt must preserve semantics before optimizing speed.&#34;</span>
</span></span><span style="display:flex;"><span> ),
</span></span><span style="display:flex;"><span> )
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">if</span> result<span style="color:#f92672">.</span>failure_reason <span style="color:#f92672">==</span> <span style="color:#e6db74">&#34;benchmark_regression&#34;</span>:
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">return</span> AttemptDiagnosis(
</span></span><span style="display:flex;"><span> failure_class<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;benchmark_regression&#34;</span>,
</span></span><span style="display:flex;"><span> prompt_lesson<span style="color:#f92672">=</span>(
</span></span><span style="display:flex;"><span> <span style="color:#e6db74">&#34;The candidate was correct but slower. &#34;</span>
</span></span><span style="display:flex;"><span> <span style="color:#e6db74">&#34;The next prompt must target a smaller hotspot and avoid extra branching or allocation.&#34;</span>
</span></span><span style="display:flex;"><span> ),
</span></span><span style="display:flex;"><span> )
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">return</span> AttemptDiagnosis(
</span></span><span style="display:flex;"><span> failure_class<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;unknown&#34;</span>,
</span></span><span style="display:flex;"><span> prompt_lesson<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;Make a smaller, safer change and preserve the baseline behavior.&#34;</span>,
</span></span><span style="display:flex;"><span> )
</span></span></code></pre></div><p>This keeps interpretation separate from mutation.</p>
<hr>
<h3 id="repair-mutates-promptstate">Repair Mutates PromptState</h3>
<p>The repair policy converts a diagnosis into a structured prompt update.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#66d9ef">def</span> <span style="color:#a6e22e">repair_prompt</span>(diagnosis):
</span></span><span style="display:flex;"><span> delta <span style="color:#f92672">=</span> PromptDelta()
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">if</span> diagnosis<span style="color:#f92672">.</span>failure_class <span style="color:#f92672">==</span> <span style="color:#e6db74">&#34;patch_apply_failed&#34;</span>:
</span></span><span style="display:flex;"><span> delta<span style="color:#f92672">.</span>system_additions<span style="color:#f92672">.</span>append(
</span></span><span style="display:flex;"><span> <span style="color:#e6db74">&#34;Return one valid unified diff against the exact target file.&#34;</span>
</span></span><span style="display:flex;"><span> )
</span></span><span style="display:flex;"><span> delta<span style="color:#f92672">.</span>banned_moves<span style="color:#f92672">.</span>extend([
</span></span><span style="display:flex;"><span> <span style="color:#e6db74">&#34;Conversational response&#34;</span>,
</span></span><span style="display:flex;"><span> <span style="color:#e6db74">&#34;Whole-file rewrite unless explicitly requested&#34;</span>,
</span></span><span style="display:flex;"><span> <span style="color:#e6db74">&#34;Touching unrelated files&#34;</span>,
</span></span><span style="display:flex;"><span> ])
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">if</span> diagnosis<span style="color:#f92672">.</span>failure_class <span style="color:#f92672">==</span> <span style="color:#e6db74">&#34;compilation_failed&#34;</span>:
</span></span><span style="display:flex;"><span> delta<span style="color:#f92672">.</span>system_additions<span style="color:#f92672">.</span>append(
</span></span><span style="display:flex;"><span> <span style="color:#e6db74">&#34;Preserve imports, function names, signatures, and public interfaces.&#34;</span>
</span></span><span style="display:flex;"><span> )
</span></span><span style="display:flex;"><span> delta<span style="color:#f92672">.</span>banned_moves<span style="color:#f92672">.</span>extend([
</span></span><span style="display:flex;"><span> <span style="color:#e6db74">&#34;Pseudocode&#34;</span>,
</span></span><span style="display:flex;"><span> <span style="color:#e6db74">&#34;Undefined symbols&#34;</span>,
</span></span><span style="display:flex;"><span> <span style="color:#e6db74">&#34;Changed public interface&#34;</span>,
</span></span><span style="display:flex;"><span> ])
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">if</span> diagnosis<span style="color:#f92672">.</span>failure_class <span style="color:#f92672">==</span> <span style="color:#e6db74">&#34;correctness_failed&#34;</span>:
</span></span><span style="display:flex;"><span> delta<span style="color:#f92672">.</span>user_additions<span style="color:#f92672">.</span>append(
</span></span><span style="display:flex;"><span> <span style="color:#e6db74">&#34;Preserve the baseline semantics before attempting performance improvements.&#34;</span>
</span></span><span style="display:flex;"><span> )
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">if</span> diagnosis<span style="color:#f92672">.</span>failure_class <span style="color:#f92672">==</span> <span style="color:#e6db74">&#34;benchmark_regression&#34;</span>:
</span></span><span style="display:flex;"><span> delta<span style="color:#f92672">.</span>user_additions<span style="color:#f92672">.</span>append(
</span></span><span style="display:flex;"><span> <span style="color:#e6db74">&#34;The previous candidate was correct but slower. &#34;</span>
</span></span><span style="display:flex;"><span> <span style="color:#e6db74">&#34;Avoid extra branching, sleeps, allocations, or unnecessary memory traffic.&#34;</span>
</span></span><span style="display:flex;"><span> )
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> delta<span style="color:#f92672">.</span>prior_lessons<span style="color:#f92672">.</span>append(diagnosis<span style="color:#f92672">.</span>prompt_lesson)
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">return</span> delta
</span></span></code></pre></div><p>The repair is explicit. It is not an improvised “try harder.”</p>
<hr>
<h3 id="promptstate-carries-the-loop-forward">PromptState Carries the Loop Forward</h3>
<p>Applying the delta creates the next state:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#66d9ef">def</span> <span style="color:#a6e22e">apply_delta</span>(state, delta):
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">return</span> PromptState(
</span></span><span style="display:flex;"><span> task_id<span style="color:#f92672">=</span>state<span style="color:#f92672">.</span>task_id,
</span></span><span style="display:flex;"><span> context_pack<span style="color:#f92672">=</span>state<span style="color:#f92672">.</span>context_pack,
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> system_prompt<span style="color:#f92672">=</span>state<span style="color:#f92672">.</span>system_prompt <span style="color:#f92672">+</span> <span style="color:#e6db74">&#34;</span><span style="color:#ae81ff">\n</span><span style="color:#e6db74">&#34;</span> <span style="color:#f92672">+</span> <span style="color:#e6db74">&#34;</span><span style="color:#ae81ff">\n</span><span style="color:#e6db74">&#34;</span><span style="color:#f92672">.</span>join(delta<span style="color:#f92672">.</span>system_additions),
</span></span><span style="display:flex;"><span> user_prompt<span style="color:#f92672">=</span>state<span style="color:#f92672">.</span>user_prompt <span style="color:#f92672">+</span> <span style="color:#e6db74">&#34;</span><span style="color:#ae81ff">\n</span><span style="color:#e6db74">&#34;</span> <span style="color:#f92672">+</span> <span style="color:#e6db74">&#34;</span><span style="color:#ae81ff">\n</span><span style="color:#e6db74">&#34;</span><span style="color:#f92672">.</span>join(delta<span style="color:#f92672">.</span>user_additions),
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> prior_lessons<span style="color:#f92672">=</span>state<span style="color:#f92672">.</span>prior_lessons <span style="color:#f92672">+</span> delta<span style="color:#f92672">.</span>prior_lessons,
</span></span><span style="display:flex;"><span> failure_warnings<span style="color:#f92672">=</span>state<span style="color:#f92672">.</span>failure_warnings <span style="color:#f92672">+</span> delta<span style="color:#f92672">.</span>failure_warnings,
</span></span><span style="display:flex;"><span> banned_moves<span style="color:#f92672">=</span>dedupe(state<span style="color:#f92672">.</span>banned_moves <span style="color:#f92672">+</span> delta<span style="color:#f92672">.</span>banned_moves),
</span></span><span style="display:flex;"><span> success_patterns<span style="color:#f92672">=</span>dedupe(state<span style="color:#f92672">.</span>success_patterns <span style="color:#f92672">+</span> delta<span style="color:#f92672">.</span>success_patterns),
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> output_contract<span style="color:#f92672">=</span>state<span style="color:#f92672">.</span>output_contract,
</span></span><span style="display:flex;"><span> attempt_index<span style="color:#f92672">=</span>state<span style="color:#f92672">.</span>attempt_index <span style="color:#f92672">+</span> <span style="color:#ae81ff">1</span>,
</span></span><span style="display:flex;"><span> )
</span></span></code></pre></div><p>The model’s weights do not change.</p>
<p>The context around the model changes.</p>
<p>That is the point.</p>
<hr>
<h3 id="artifacts-are-written-at-every-step">Artifacts Are Written at Every Step</h3>
<p>A real run writes the evidence trail:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#66d9ef">def</span> <span style="color:#a6e22e">write_attempt_artifacts</span>(state, result, diagnosis, delta):
</span></span><span style="display:flex;"><span> write(<span style="color:#e6db74">&#34;attempts/</span><span style="color:#e6db74">{id}</span><span style="color:#e6db74">/prompt.md&#34;</span>, state<span style="color:#f92672">.</span>render())
</span></span><span style="display:flex;"><span> write(<span style="color:#e6db74">&#34;attempts/</span><span style="color:#e6db74">{id}</span><span style="color:#e6db74">/result.json&#34;</span>, result)
</span></span><span style="display:flex;"><span> write(<span style="color:#e6db74">&#34;attempts/</span><span style="color:#e6db74">{id}</span><span style="color:#e6db74">/diagnosis.md&#34;</span>, diagnosis)
</span></span><span style="display:flex;"><span> write(<span style="color:#e6db74">&#34;attempts/</span><span style="color:#e6db74">{id}</span><span style="color:#e6db74">/next_prompt_delta.md&#34;</span>, delta)
</span></span></code></pre></div><p>Prompt states get their own timeline:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#66d9ef">def</span> <span style="color:#a6e22e">write_prompt_state</span>(state):
</span></span><span style="display:flex;"><span> write(<span style="color:#e6db74">&#34;prompt_states/</span><span style="color:#e6db74">{id}</span><span style="color:#e6db74">/prompt.md&#34;</span>, state<span style="color:#f92672">.</span>render())
</span></span></code></pre></div><p>The larger pipeline then packages everything:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#66d9ef">def</span> <span style="color:#a6e22e">full_pipeline</span>(task_pack):
</span></span><span style="display:flex;"><span> run <span style="color:#f92672">=</span> solve_task_pack(task_pack)
</span></span><span style="display:flex;"><span> bundle <span style="color:#f92672">=</span> build_run_bundle(run)
</span></span><span style="display:flex;"><span> submission <span style="color:#f92672">=</span> package_submission(bundle)
</span></span><span style="display:flex;"><span> export <span style="color:#f92672">=</span> export_platform_submission(submission)
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">return</span> validate(export)
</span></span></code></pre></div><p>That is the full system in miniature.</p>
<p>The implementation is larger because it has registries, validators, manifests, hashes, and CLI commands. But the idea remains the same:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-text" data-lang="text"><span style="display:flex;"><span>generate
</span></span><span style="display:flex;"><span>→ validate
</span></span><span style="display:flex;"><span>→ diagnose
</span></span><span style="display:flex;"><span>→ repair
</span></span><span style="display:flex;"><span>→ try again
</span></span><span style="display:flex;"><span>→ preserve the evidence
</span></span></code></pre></div><p>That is Codex Manager.</p>
<hr>
<h2 id="glossary">Glossary</h2>
<table>
<thead>
<tr>
<th><strong>Term</strong></th>
<th><strong>Definition</strong></th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>Codex Manager</strong></td>
<td>A prompt-state runtime that manages Codex through candidate generation, isolated execution, diagnosis, repair, and verified promotion.</td>
</tr>
<tr>
<td><strong>PromptState</strong></td>
<td>The structured state around Codex at a given point in the run, including context, prior lessons, failure warnings, banned moves, success patterns, and the output contract.</td>
</tr>
<tr>
<td><strong>Candidate</strong></td>
<td>A proposed solution generated by Codex or another candidate executor. It is treated as a proposal, not as a trusted answer.</td>
</tr>
<tr>
<td><strong>Candidate Diff</strong></td>
<td>A patch generated by the model, usually as a unified diff against the target file.</td>
</tr>
<tr>
<td><strong>Attempt</strong></td>
<td>One cycle of generating a candidate, applying it, validating it, benchmarking it, and recording the result.</td>
</tr>
<tr>
<td><strong>AttemptResult</strong></td>
<td>The structured evidence from an attempt, including whether the candidate applied, built, passed correctness, passed benchmark, and improved performance.</td>
</tr>
<tr>
<td><strong>AttemptDiagnosis</strong></td>
<td>The manager’s interpretation of an AttemptResult. It identifies what failed, why it likely failed, and what lesson should carry forward.</td>
</tr>
<tr>
<td><strong>PromptDelta</strong></td>
<td>A structured update to the next PromptState, such as new constraints, warnings, banned moves, or success patterns.</td>
</tr>
<tr>
<td><strong>Prompt Repair</strong></td>
<td>The process of converting an AttemptDiagnosis into a PromptDelta so the next attempt is generated under better constraints.</td>
</tr>
<tr>
<td><strong>Banned Moves</strong></td>
<td>Actions the next candidate should avoid, such as touching test files, changing public interfaces, assuming aligned inputs, or returning prose instead of a diff.</td>
</tr>
<tr>
<td><strong>Success Patterns</strong></td>
<td>Patterns from successful attempts that should be preserved in future attempts.</td>
</tr>
<tr>
<td><strong>Context Pack</strong></td>
<td>The task-specific context given to Codex, including the goal, source constraints, correctness contract, benchmark contract, known failure modes, and output contract.</td>
</tr>
<tr>
<td><strong>Task Pack</strong></td>
<td>A portable YAML or JSON task definition that describes the problem, source files, target file, allowed patch paths, build command, correctness command, benchmark command, and context.</td>
</tr>
<tr>
<td><strong>Execution Mode</strong></td>
<td>The way a task is evaluated, such as <code>shadow</code>, <code>shadow_mock</code>, or <code>command</code>.</td>
</tr>
<tr>
<td><strong>Shadow Workspace</strong></td>
<td>An isolated copy of the source files where candidate patches are applied and tested without modifying the real source tree.</td>
</tr>
<tr>
<td><strong>Patch Gate</strong></td>
<td>The validation step that checks whether a candidate diff applies cleanly and only touches allowed files.</td>
</tr>
<tr>
<td><strong>Build Gate</strong></td>
<td>The validation step that checks whether the patched target still compiles or passes its build command.</td>
</tr>
<tr>
<td><strong>Correctness Gate</strong></td>
<td>The validation step that checks whether the candidate preserves the required behavior. Benchmarking is blocked unless this passes.</td>
</tr>
<tr>
<td><strong>Benchmark Gate</strong></td>
<td>The validation step that measures whether a correctness-passing candidate improves performance.</td>
</tr>
<tr>
<td><strong>Benchmark Regression</strong></td>
<td>A failure where the candidate passes correctness but performs worse than the baseline.</td>
</tr>
<tr>
<td><strong>Verified Promotion</strong></td>
<td>The decision to mark a candidate as the best surviving attempt only after it passes the required gates and improves the benchmark.</td>
</tr>
<tr>
<td><strong>Candidate Executor</strong></td>
<td>The component that turns a PromptState into a candidate. Examples include mock, scripted, and OpenAI-compatible executors.</td>
</tr>
<tr>
<td><strong>Executor Registry</strong></td>
<td>The registry that lets Codex Manager switch between candidate generators without changing the prompt-state loop.</td>
</tr>
<tr>
<td><strong>Profile</strong></td>
<td>A domain-specific evaluator for a class of tasks. For example, a kernel optimization profile knows how to build context and run candidates for kernel-style tasks.</td>
</tr>
<tr>
<td><strong>Profile Registry</strong></td>
<td>The registry that lets Codex Manager load different profiles without hardcoding execution paths into the engine.</td>
</tr>
<tr>
<td><strong>Command Adapter</strong></td>
<td>The execution path that lets task packs define shell commands for build, correctness, and benchmark evaluation.</td>
</tr>
<tr>
<td><strong>Run Bundle</strong></td>
<td>A reproducible package of a completed run, including the run manifest, context pack, prompt log, report, validation output, replay script, attempts, and best candidate evidence.</td>
</tr>
<tr>
<td><strong>Submission Package</strong></td>
<td>A judge-ready artifact built from a run bundle, containing the evidence needed to inspect the run and its promoted candidate.</td>
</tr>
<tr>
<td><strong>Platform Export</strong></td>
<td>A translated version of the submission package shaped for a specific external platform, such as <code>generic_command</code>, <code>metal_stub</code>, or <code>gpu_mode_stub</code>.</td>
</tr>
<tr>
<td><strong>Pipeline</strong></td>
<td>The full end-to-end workflow: task pack, solve, run bundle, submission package, platform export, and validation.</td>
</tr>
<tr>
<td><strong>Pipeline Manifest</strong></td>
<td>The machine-readable summary of a full pipeline run, including IDs, output paths, validations, and chain-of-custody hashes.</td>
</tr>
<tr>
<td><strong>Chain of Custody</strong></td>
<td>The hash-linked trail connecting a run bundle, submission package, and platform export.</td>
</tr>
<tr>
<td><strong>PROMPTS.log</strong></td>
<td>The append-only JSONL log of prompt attempts, prompt hashes, diagnoses, speedups, promotion status, and executor metadata.</td>
</tr>
<tr>
<td><strong>attempts/</strong></td>
<td>The directory containing executed attempts. Each attempt contains the prompt, result, diagnosis, and next prompt delta.</td>
</tr>
<tr>
<td><strong>prompt_states/</strong></td>
<td>The directory containing PromptState snapshots, including future prompt states that may not have been executed.</td>
</tr>
<tr>
<td><strong>Replay</strong></td>
<td>The ability to inspect or rerun a task using the recorded task pack, manifest, and pipeline metadata.</td>
</tr>
<tr>
<td><strong>Context Machine</strong></td>
<td>The broader system around Codex that preserves state, evaluates attempts, repairs prompts, and produces artifacts. Codex Manager is the context machine described in this post.</td>
</tr>
</tbody>
</table>
</div>
<footer class="post__footer">
<div class="post__tags tags clearfix">
<svg class="tags__badge icon icon-tag" width="16" height="16" viewBox="0 0 32 32"><path d="M4 0h8s2 0 4 2l15 15s2 2 0 4L21 31s-2 2-4 0L2 16s-2-2-2-4V3s0-3 4-3m3 10a3 3 0 0 0 0-6 3 3 0 0 0 0 6"/></svg>
<ul class="tags__list">
<li class="tags__item">
<a class="tags__link btn" href="/tags/ai-coding/" rel="tag">AI Coding</a>
</li>
<li class="tags__item">
<a class="tags__link btn" href="/tags/prompt-engineering/" rel="tag">Prompt Engineering</a>
</li>
<li class="tags__item">
<a class="tags__link btn" href="/tags/agentic-systems/" rel="tag">Agentic Systems</a>
</li>
<li class="tags__item">
<a class="tags__link btn" href="/tags/software-architecture/" rel="tag">Software Architecture</a>
</li>
<li class="tags__item">
<a class="tags__link btn" href="/tags/developer-tools/" rel="tag">Developer Tools</a>
</li>
<li class="tags__item">
<a class="tags__link btn" href="/tags/hackathon/" rel="tag">Hackathon</a>
</li>
<li class="tags__item">
<a class="tags__link btn" href="/tags/codex/" rel="tag">Codex</a>
</li>
<li class="tags__item">
<a class="tags__link btn" href="/tags/context-engineering/" rel="tag">Context Engineering</a>
</li>
<li class="tags__item">
<a class="tags__link btn" href="/tags/code-generation/" rel="tag">Code Generation</a>
</li>
<li class="tags__item">
<a class="tags__link btn" href="/tags/reproducibility/" rel="tag">Reproducibility</a>
</li>
<li class="tags__item">
<a class="tags__link btn" href="/tags/meta-agents/" rel="tag">Meta-Agents</a>
</li>
<li class="tags__item">
<a class="tags__link btn" href="/tags/verification/" rel="tag">Verification</a>
</li>
</ul>
</div>
</footer>
</article>
</main>
<div class="authorbox clearfix">
</div>
</div>
</div>
<footer class="footer">
<div class="container footer__container flex">
</div>
</footer>
</div>
<script async defer src="/js/menu.js"></script>
<script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js?config=TeX-AMS-MML_HTMLorMML" async></script>
<script type="module">
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.esm.min.mjs';
mermaid.initialize({ startOnLoad: true });
</script>
</body>
</html>