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;