Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions hooks/useAgentSession.rpc.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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/<id> read
// 404s while the live RPC wrapper answers /api/agent/<id> 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")]);
Expand Down
7 changes: 7 additions & 0 deletions hooks/useAgentSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading