From 86a7542196d0130acf610590d60e92cc16e0ec81 Mon Sep 17 00:00:00 2001 From: utsmok Date: Thu, 1 Oct 2026 19:50:00 +0000 Subject: [PATCH] fix(agent-session): send prompts to sessions with no on-disk transcript yet A session whose prompts were all local slash commands never started an agent run, so omp writes no session file. snapshotRunEntries threw on the 404 from the boundary read, which sits before prompt dispatch, so the send failed with 'HTTP 404' and follow-up messages were dropped. Treat that 404 as an empty baseline, the same way loadSession already tolerates the missing file. Add a regression test. --- hooks/useAgentSession.rpc.test.mjs | 29 +++++++++++++++++++++++++++++ hooks/useAgentSession.ts | 7 +++++++ 2 files changed, 36 insertions(+) diff --git a/hooks/useAgentSession.rpc.test.mjs b/hooks/useAgentSession.rpc.test.mjs index 32e4faebf..5e48ed6a7 100644 --- a/hooks/useAgentSession.rpc.test.mjs +++ b/hooks/useAgentSession.rpc.test.mjs @@ -1332,6 +1332,35 @@ test("abort_and_prompt: the aborted run's terminal agent_end is consumed, the ne assert.equal(w.latest.streamState.streamingMessage?.content?.[0]?.text, "new run streaming"); }); +test("send tolerates a missing session file (local-only slash commands) and still dispatches", async () => { + resetWorld(); + // A session whose only prompts were local slash commands never started an + // agent run, so omp wrote no session file: every /api/sessions/ read + // 404s while the live RPC wrapper answers /api/agent/ normally. + world.agents.set("fileless", { running: false, state: {} }); + const w = await mountSession("fileless"); + assert.equal(w.latest.loading, false, "hydration completes without a file"); + assert.equal(w.latest.agentRunning, false); + + let sendPromise; + await act(async () => { + sendPromise = w.latest.handleSend("hello after skill"); + await sleep(30); + }); + const es = lastEs(); + await act(async () => { + es.open(); + await sendPromise; + }); + assert.equal( + callsTo("POST", "/api/agent/fileless").some((c) => c.body?.type === "prompt" && c.body?.message === "hello after skill"), + true, + "prompt must be dispatched despite the boundary 404", + ); + assert.equal(w.latest.agentRunning, true, "run starts optimistically"); + assert.equal(w.latest.notices.length, 0, "no failed-send notice"); +}); + test("a reconcile response that straddles a run boundary is dropped by the run-id fence", async () => { resetWorld(); primeSession("s1", [userMsg("u0", "q")]); diff --git a/hooks/useAgentSession.ts b/hooks/useAgentSession.ts index 34e0b8a0e..1748bb76e 100644 --- a/hooks/useAgentSession.ts +++ b/hooks/useAgentSession.ts @@ -2470,6 +2470,13 @@ export function useAgentSession(opts: UseAgentSessionOptions) { // the previous terminal reload or interrupted turn can still be in flight. // Unlike loadSession, this must not replace the optimistic user bubble. const res = await fetch(`/api/sessions/${encodeURIComponent(sid)}/context?boundary=1`); + if (res.status === 404) { + // A session whose prompts so far were all local slash commands (skill + // activation, …) never started an agent run, so omp wrote no session + // file yet. There is no prior run to diff against — proceed with an + // empty baseline instead of failing the send. + return []; + } if (!res.ok) throw new Error(`HTTP ${res.status}`); const snapshot = await res.json() as { entryIds: string[] }; return snapshot.entryIds;