<p><strong>Elyra's </strong><code>/bisect</code><strong> — finding the exact turn that broke things</strong></p><p>There's a special kind of frustration that comes from working with an AI agent across a long session. You started with working code. Twenty turns later, something is broken. The agent edited a dozen files across those turns, and somewhere in there — you don't know where — it introduced the bug.</p><p>Your options are bad. Scroll back through twenty turns of conversation hoping to spot it. Or <code>git diff</code> the whole mess and read every change. Or just <code>/rewind</code> to some earlier point and lose all the good work that came after the bug.</p><p>Git solved this exact problem for commits decades ago: <code>git bisect</code>. Binary-search your history, test at each step, and it tells you precisely which commit introduced the regression. Elyra's <code>/bisect</code> does the same thing — but over the agent's own turns.</p><p>As far as I know, no other coding agent can do this. And the reason is interesting.</p><h2>Why only Elyra can do this</h2><p><code>git bisect</code> works because git has a commit at every point in history. To bisect, you need a restorable snapshot at each step.</p><p>Most agents don't have that. They edit files in place; the only record of "what the code looked like at turn 12" is gone the moment turn 13 overwrites it.</p><p>Elyra is different. Before <em>every single turn</em>, it quietly snapshots your working tree using a git primitive (<code>git stash create</code>) that captures the state without disturbing anything. This is the same machinery that powers <code>/rewind</code>. It means Elyra has a restorable filesystem snapshot tied to every point in the conversation.</p><p>That's the missing ingredient. Once you have a snapshot per turn, bisecting over them is just binary search.</p><h2>How it works</h2><p>Say your test suite passes at the start of a session and fails now. You run:</p><pre><code class="language-text">/bisect npm test
</code></pre><p>Elyra treats this exactly like <code>git bisect run</code>:</p><pre><code class="language-typescript">// 1. Confirm the current state is actually broken
if ((await runCommand()) === 0) {
    // "Current state passes — nothing to bisect."
}

// 2. Confirm the earliest checkpoint was good
// 3. Binary search between good (lo) and bad (hi)
while (hi - lo &gt; 1) {
    const mid = Math.floor((lo + hi) / 2);
    this.session.restoreFilesToCheckpoint(points[mid].entryId);
    const good = (await runCommand()) === 0;   // exit 0 = good
    if (good) lo = mid;
    else hi = mid;
}
// points[hi] is the first bad checkpoint
</code></pre><p>It restores the working tree to a checkpoint, runs <code>npm test</code>, and uses the exit code: zero means the bug wasn't there yet, non-zero means it was. Binary search halves the suspects each step. Twenty turns? Five tests. A hundred? Seven.</p><p>And then it tells you exactly which turn introduced the failure:</p><pre><code class="language-text">First bad checkpoint: "Refactor the payment validation to use the new schema"
The change introduced at this turn is the likely culprit. Use /rewind to return here.
</code></pre><p>No command? No problem:</p><pre><code class="language-text">/bisect
</code></pre><p>This runs it manually — Elyra restores the files to each midpoint and asks you to test (in another terminal or by inspecting) and mark it Good or Bad.</p><h2>The safety net</h2><p>Repeatedly restoring your working tree is exactly the kind of thing that could lose work if it goes wrong. So bisect snapshots your <em>current</em> state before it starts, and restores it in a <code>finally</code> block no matter how the search ends — found, aborted, or errored:</p><pre><code class="language-typescript">const snapshot = this.session.createWorkingTreeSnapshot();
try {
    // ... the whole bisect search ...
} finally {
    this.session.restoreFilesToSnapshot(snapshot);  // always
}
</code></pre><p>You end exactly where you started, plus the knowledge of which turn broke things. Then one <code>/rewind</code> puts you back at that point to fix it properly.</p><h2>Why it matters</h2><p>The longer you let an agent run, the more valuable this becomes — and the more agents are being pushed toward long, autonomous sessions. But long autonomy has a cost: when something breaks, the haystack is huge.</p><p><code>/bisect</code> turns "somewhere in the last hundred turns" into "this exact turn, in seven tests." It's the debugging primitive that long-running agents have been missing, and it falls out naturally from an architecture that snapshots state at every step.</p><pre><code class="language-text">/bisect npm test
</code></pre>