Durable coding-agent harnesses (Claude Code, Codex, OpenCode, Pi, fx) on a Workflow SDK World
harness-opencode/test: the crashed drive's stand-in host stops sending at the crash (fixes CI on main) (#15)
Pranay Prakashdda5ef277452
diff --git a/docs/followups.md b/docs/followups.mdindex 6830299..b40f73c 100644--- a/docs/followups.md+++ b/docs/followups.md@@ -28,3 +28,14 @@ reworked for it:"files last across VMs" covers the next worker's higher token. It needs thesecond worker in a process of its own, with the Sandbox stand-in sharedbetween them.++## Live writes after a takeover++A drive's live events aren't fenced: what a drive sends after another drive+has taken the session over still lands in the session's live stream. OpenCode's+"a crash while the model streams" test showed it. Its in-process crash kept+the first drive's stand-in host streaming the cut-off reply, and those deltas+landed after the next drive's `restart` event, interleaved with the resumed+reply. The test now stops the stand-in at the crash, as a real crash does.+A driver that is still running after a takeover (a stalled process) could+do the same. Its live writes need the drive's fence, as its log writes have.diff --git a/packages/harness-opencode/src/harness.test.ts b/packages/harness-opencode/src/harness.test.tsindex 8bec22b..c19380f 100644--- a/packages/harness-opencode/src/harness.test.ts+++ b/packages/harness-opencode/src/harness.test.ts@@ -344,24 +344,27 @@ describe('the OpenCode drive', () => {models.push(model);const dataDir = await mkdtemp(join(tmpdir(), 'oc-fake-'));let crashed!: () => void;- const died = new Promise<void>((r) => (crashed = r));+ // A real crash takes the process's OpenCode host with it: the stand-in host stops sending at the crash.+ let dead = false;+ const died = new Promise<void>((r) => (crashed = () => ((dead = true), r())));const mail = { to: '[email protected]', subject: 'hi', body: 'x' };/** OpenCode's model request: through the drive's proxy (`gatewayBaseURL`), after the barrier. */- const ask = async (h: FakeHost, text: string) => {+ const ask = async (h: FakeHost, text: string, alive = () => true) => {await h.request({ type: 'barrier', kind: 'primary' });- await streamFromModel(`${h.init.gatewayBaseURL}/language-model`, text, (delta) => h.send({ type: 'text', delta }), { authorization: `Bearer ${h.init.gatewayKey}` });+ await streamFromModel(`${h.init.gatewayBaseURL}/language-model`, text, (delta) => alive() && h.send({ type: 'text', delta }), { authorization: `Bearer ${h.init.gatewayKey}` });};+ const before = () => !dead;const first: Script = async (h) => {open(h);await admit(h);- await ask(h, 'Sending it.');+ await ask(h, 'Sending it.', before);h.commit(['session.step.started'], ['session.text.ended', { text: 'Sending it.' }], ['session.tool.input.started', { id: 'toolu_mail', name: 'unsafe_send_email' }], ['session.tool.called',{ id: 'toolu_mail', input: mail },]);const r = await h.request({ type: 'tool', callId: 'toolu_mail', name: 'unsafe_send_email', input: mail });h.commit(['session.tool.success', { id: 'toolu_mail', content: [{ type: 'text', text: r.ok ? r.text : '' }] }], ['session.step.ended']);- await ask(h, `unsafe_send_email returned: ${r.ok ? r.text : ''}`);+ await ask(h, `unsafe_send_email returned: ${r.ok ? r.text : ''}`, before);};let note = '';const second: Script = async (h) => {@@ -411,8 +414,7 @@ describe('the OpenCode drive', () => {expect(live[restart]).toEqual({ type: 'restart', text: 'Sending it.', parts: ['Sending it.'] });const text = (from: number, to: number) => live.slice(from, to).flatMap((e) => (e.type === 'text' ? [e.delta] : [])).join('');expect(text(0, restart)).toMatch(/^Sending it\..+/);- // The stand-in's crashed host can still stream a few deltas as the next drive starts (a real crash writes nothing more).- expect(text(restart + 1, live.length)).toMatch(/Recovered from the log: the email went out\.$/);+ expect(text(restart + 1, live.length)).toBe('Recovered from the log: the email went out.');expect(b.errors).toEqual([]);});